Skip to content

Fix Shortcode context for v2 blocks#2919

Merged
gcushen merged 1 commit intoHugoBlox:mainfrom
Agos95:shortcode-context-fix
Feb 13, 2023
Merged

Fix Shortcode context for v2 blocks#2919
gcushen merged 1 commit intoHugoBlox:mainfrom
Agos95:shortcode-context-fix

Conversation

@Agos95
Copy link
Copy Markdown
Contributor

@Agos95 Agos95 commented Feb 11, 2023

Purpose

Shortcodes in the new block system do not get access to the correct .Page variable (see #2918 ). The problem is the use of markdownify function to parse $block.content.text, since it actually is an alias to site.Home.RenderString since v 0.93.0 (see gohugoio/hugo#9959 (comment)).

This causes the shortcodes to always get the Homepage as .Page variable. The fix is to substitute markdownify with $page.RenderString, which gives the correct context.

An actual example of this behaviour can be found in this branch (in the csv page):

screenshot_2023-02-11_16-46
screenshot_2023-02-11_16-46_1

This PR fixes #2918.

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 11, 2023

Deploy Preview for hugo-portfolio-theme canceled.

Name Link
🔨 Latest commit 75c6514
🔍 Latest deploy log https://app.netlify.com/sites/hugo-portfolio-theme/deploys/63e7b8c41494dc00076e1cbc
@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 11, 2023

Deploy Preview for markdown-slides canceled.

Name Link
🔨 Latest commit 75c6514
🔍 Latest deploy log https://app.netlify.com/sites/markdown-slides/deploys/63e7b8c40898b900081c5670
@gcushen
Copy link
Copy Markdown
Collaborator

gcushen commented Feb 12, 2023

Thanks for contributing a solution 🎉

Before we merge this, can you check if we still need to include the emojify logic or if Hugo is now smart enough to use the emojify: true site setting in config.yaml in its RenderString function?

@gcushen gcushen added the bug label Feb 12, 2023
@gcushen gcushen changed the title Fix Shortcode context for blocks Feb 12, 2023
@Agos95
Copy link
Copy Markdown
Contributor Author

Agos95 commented Feb 13, 2023

I tried, but emojify logic is still required to render emoji.

@gcushen gcushen merged commit f55ff59 into HugoBlox:main Feb 13, 2023
@jbsilva jbsilva mentioned this pull request Feb 13, 2023
2 tasks
@Agos95 Agos95 deleted the shortcode-context-fix branch April 28, 2023 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 participants