简体   繁体   中英

smarty include markdown file

I want to include a markdown file in my Smarty template.

In PHP I have this:

$smarty->assign('text', 'PATH_TO_FILE/text.md');

in the template I use:

{include file=$text}

but this returns an unformated block of text.

I tried using David Scherer's markdown plugin for Smarty:

{markdown text=$text} 

but this just returns the file path stored in the $text variable.

How do I get Smarty to parse an included file as markdown?

You could instead read the file and assign the contents to the variable, then use the markdown plugin.

$smarty->assign('text', file_get_contents('PATH_TO_FILE/text.md'));

Manual page for file_get_contents()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM