themosis / theme

The Themosis framework theme.
http://framework.themosis.com/
GNU General Public License v2.0
104 stars 35 forks source link

Shortcodes with Twig template #34

Closed MorganAkki closed 6 years ago

MorganAkki commented 6 years ago

Hello,

In my template I use {{ wpautop(post.post_content)|raw }} to display the content of my page. But HTML from shortcodes are not display. I also tried wptexturize(). If I add {{ wpautop(fn.do_shortcode(post.post_content))|raw }}, it works.

Is there a better solution? Thank you for your help.

jlambe commented 6 years ago

Not really. By default, the post_content property is only holding a large string. It is through WordPress/PHP helper functions that some HTML tags and shortcodes are "compiled".

You can use the WordPress filter content so it behaves like on default templates:

{{ fn.apply_filters('content', post.post_content)|raw }}
MorganAkki commented 6 years ago

This filter already exist or do I have to create it ? Because it does'nt work in my case. Did I miss something in my theme configuration ?

jlambe commented 6 years ago

Or perhaps it is the_content for its name. Yes it is a core filter used by WordPress. Used into the the_content() template function for example.

MorganAkki commented 6 years ago

Perfect! Thank you for your help 👍