[solved] ProcessTemplateFromData method in CMSModule

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

[solved] ProcessTemplateFromData method in CMSModule

Post by psy »

Just discovered in the API docs that this popular method is deprecated and scheduled for removal.

ProcessTemplateFromData (line 2937)

Given a template in a variable, this method processes it through smarty note, there is no caching involved.

Note: this function is deprecated and scheduled for removal.

deprecated:
final:
access: public

string ProcessTemplateFromData (data $data)

data $data: Input template
Would someone please tell me how to achieve the same result now.

Thanks
psy
Last edited by psy on Sun Aug 19, 2012 2:06 pm, edited 1 time in total.
Jos
Support Guru
Support Guru
Posts: 4017
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: ProcessTemplateFromData method in CMSModule

Post by Jos »

I didn't test myself, but maybe this post gives you a hint?
http://forum.cmsmadesimple.org/viewtopi ... 75#p284375
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: ProcessTemplateFromData method in CMSModule

Post by psy »

Thanks Jos

Calguy's solution only works when you have plain text. It crashes when you have smarty tags within the text. What I want to do is what the old method did, ie evaluate the field contents before returning the output.

I've read (tho probably not fully comprehended) the smarty docs and still can't figure out how to do it.

Any other suggestions?

psy
Jos
Support Guru
Support Guru
Posts: 4017
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: ProcessTemplateFromData method in CMSModule

Post by Jos »

Where did you actually read that it is deprecated?
It is not stated here http://www.cmsmadesimple.org/apidoc/CMS ... teFromData
and as far as I know that's the official API Doc.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: ProcessTemplateFromData method in CMSModule

Post by psy »

Hi Jos

Yes, that's where I read it:

ProcessTemplateFromData (line 2937)

Given a template in a variable, this method processes it through smarty note, there is no caching involved.

Note: this function is deprecated and scheduled for removal.

deprecated:
final:
access: public

string ProcessTemplateFromData (data $data)

data $data: Input template
http://www.cmsmadesimple.org/apidoc/CMS ... teFromData
Jos
Support Guru
Support Guru
Posts: 4017
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: ProcessTemplateFromData method in CMSModule

Post by Jos »

Ok.. I had to do a ctrl-F5 :-X
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

[solved] Re: ProcessTemplateFromData method in CMSModule

Post by psy »

Calguy's post helped but it wasn't the full answer. Actually found the solution by reading through the index.php code. There was a comment around line 226

Code: Select all

	    // in smarty 3, we could use eval:{content} I think.
	    //$html = $smarty->fetch('eval:{content}')."\n";
I got it working in the yet-to-be-released next version SEOTools2 by replacing ProcessTemplateFromData with:

Code: Select all

  $title = $this->GetPreference('title','{title} | {sitename} - {seo_keywords}');
  $title = $smarty->fetch('eval:'.$title);

where $title contained a mixture of text and tags and I didn't want to display the output immediately.

hth
psy
Jos
Support Guru
Support Guru
Posts: 4017
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: [solved] ProcessTemplateFromData method in CMSModule

Post by Jos »

Seems to work just fine, thank you!

But I would also be interested into how to make it backwards compatible to CMSms 1.10?

Also I ask myself why it would be necessary to break plugins and modules for such a little convenient function ???
Maybe the deprecated status on ProcessTemplateFromData could be reconsidered?
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: [solved] ProcessTemplateFromData method in CMSModule

Post by psy »

A good question for the dev team, along with others like why has "CreateToolTipLink" been deprecated? Very handy little method and the only alternative I found was the cumbersome "CreateLink".
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: [solved] ProcessTemplateFromData method in CMSModule

Post by calguy1000 »

Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: [solved] ProcessTemplateFromData method in CMSModule

Post by psy »

Thanks Calguy. Understand better now how it works.

FWIW, below are results returned when using the new smarty method to compile the main content block of a page, content_en, programmatically from within a module admin area:

{sitename} : worked correctly and displayed the correct sitename

{title} : compiled but displayed "404 Error"

{cms_module module=News} : compiled and displayed correctly

{news} : returned error "Warning: file(C:\wamp\www\xxx\lib\smarty\sysplugins\smarty_internal_templatebase.php(147) : eval()'d code) [function.file]: failed to open stream: No such file or directory in C:\wamp\www\xxx\lib\misc.functions.php on line 2263"

{cms_selflink} : compiled and displayed correctly

{custom_copyright} - crashed badly with "Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "2578f763fa0bd97b6b8e3f65fcbab500098a6933" on line 1 "<p>Congratulations! The installation worked. You now have a fully functional installation of CMS Made Simple and you are <em>almost</em> ready to start building your site.<br /><br />{custom_copyright}<br /><br />This is the site name {sitename}<br />this is the title {title}<br /><br />full module tag: {cms_module module=News}<br />plugin form of News tag {news}<br />cms selflink tag: <a href="{cms_selflink href='how-cmsms-works'}">How CMSMS Works</a><br /><br /><br /></p>" unknown tag "custom_copyright"' in C:\wamp\www\xxx\lib\smarty\sysplugins\smarty_internal_templatecompilerbase.php:656 Stack trace: #0 C:\wamp\www\xxx\lib\smarty\sysplugins\smarty_internal_templatecompilerbase.php(441): Smarty_Internal_TemplateCompilerBase->trigger_temp in C:\wamp\www\xxx\lib\smarty\sysplugins\smarty_internal_templatecompilerbase.php on line 656"

{$myvar} - var assigned in page template out of scope of {content} : did not compile which is understandable however rather than ignoring the var it returned the error "Notice: Undefined index: myvar in C:\wamp\www\xxx\lib\smarty\sysplugins\smarty_internal_templatebase.php(147) : eval()'d code on line 13

Notice: Trying to get property of non-object in C:\wamp\www\xxx\lib\smarty\sysplugins\smarty_internal_templatebase.php(147) : eval()'d code on line 13
"

In short, seemed that core modules and plugins compiled but any tag that was user related, esp the UDT had problems.

Not passing any comments or judgements, just giving some feedback on results of my testing in the hope they may be useful to dev team.

psy
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: [solved] ProcessTemplateFromData method in CMSModule

Post by calguy1000 »

User defined tags are not loaded in the admin in 1.11

"eval:{content}" and "eval:{content_image}" and other such tags will not work in the admin as there is no concept of a current frontend page when working in the admin.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: [solved] ProcessTemplateFromData method in CMSModule

Post by psy »

Good to know. Thanks.

Code being tested was:

Code: Select all

$output .= '<div class="pageinput">'.$smarty->fetch('eval:' . $content_obj->GetPropertyValue('content_en')).'</div>';
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: [solved] ProcessTemplateFromData method in CMSModule

Post by psy »

User defined tags are not loaded in the admin in 1.11
Does module_custom still work?

There have been occasions in the past when a client has wanted something unique in the admin area of a module and I've used this dir to override the default admin template and included UDTs.
Post Reply

Return to “Developers Discussion”