You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created a module for myself and got frustrated how inflexible phpwcms own template language is, especially the conditional statements with [REPLACEMENT_TAG_ELSE]. I think it's time to slowly move or offer, something like Twig while keeping the "old" way intact.
This is a quick example with loading template fragments:
// twig is included via composer/autoload.php$twig = new \Twig_Environment(new \Twig_Loader_String());
$data = [
'AUTHOR' => 'Mark Twain',
'TITLE' => 'The Awful German Language'
];
$template = get_file_contents('tmpl.twig');
// render twig$TMP = $twig->render($template, $data);
// old way to keep old code intact$TMP = render_cnt_template($TMP, 'AUTHOR', $rss['item_author'] ? $rss['item_author'] : '' );
The text was updated successfully, but these errors were encountered:
marcus-at-localhost
changed the title
Provide Twig Template Engine in Addition to Homebrew Replacement Tags
Provide Twig Template Engine in Addition to Own Replacement Tags
Nov 8, 2017
This is for something BIGGER and needs refactoring code and logic. You can really see how old rendering inside of phpwcms is. First content parts needs to be split into something generic, kind a bit like I have done with custom fields. I cannot say if I like Twig or not. I don't like the {% %} inside of templates. My favourite would be something <phpwcms:if ></phpwcms:if>. But I know this is not the point ;-)
I agree – templating needs to be more common so you would be able to easily adopt existing templates.
But I would guess overhead of render_cnt_template() is much smaller than Twig on top. But I know it's not perfect and lacks a lot of flexibility in case of looping and so on.
I created a module for myself and got frustrated how inflexible phpwcms own template language is, especially the conditional statements with
[REPLACEMENT_TAG_ELSE]
. I think it's time to slowly move or offer, something like Twig while keeping the "old" way intact.This is a quick example with loading template fragments:
I think it would help cleaning up core code too.
The only concerns I would have is performance when this is used to render every single content part and as I found out now,
Twig_Loader_String
is not the recommended way to load template strings: https://stackoverflow.com/questions/31081910/what-to-use-instead-of-twig-loader-string.Thoughts?
The text was updated successfully, but these errors were encountered: