Write a Hugo Shortcodes to embed Telegram post
Table of Contents
Create your own Shortcodes to Embed Telegram post.
You can extend Hugo’s built-in shortcodes by creating your own using the same templating syntax as that for single and list pages.
Hugo documents
File Location
To create a shortcode, place an HTML template in the
layouts/shortcodes
directory of your source organization. Consider the file name carefully since the shortcode name will mirror that of the file but without the.html
extension.
telegramPost.html
Create telegramPost.html
inside layouts/shortcodes
<div id="tgPost">
<script type="text/javascript"></script>
<script
async
src="https://telegram.org/js/telegram-widget.js?15"
data-telegram-post="{{ .Get 0 }}/{{ .Get 1}}"
data-width="100%"
></script>
</div>
layouts/shortcodes/telegramPost.html
will be called with{{< telegramPost channelName PostId >}}
For instance:
{{< telegramPost programmerjokes 2246 >}}