Get and replace content_page before sending to browser with UDT

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
Sonya

Get and replace content_page before sending to browser with UDT

Post by Sonya »

Hello,

I am trying to write an UDT which gets the smarty parsed content just before sending it to browser and replace some words with links. Something like this:

Code: Select all

global $gCms;
$pagecontent = str_replace('word','<a href="#">word</a>',$pagecontent);
My problem is: I do not know how to get parsed page content of the actual page in my UDT. In my example the variable I'm looking for is $pagecontent.

Thank you for your help.
Sonya
alby

Re: Get and replace content_page before sending to browser with UDT

Post by alby »

Sonya wrote: My problem is: I do not know how to get parsed page content of the actual page in my UDT. In my example the variable I'm looking for is $pagecontent.
Many option:

1:
- create a modifier smarty (view smarty doc)

2:
- capture {content} and assign to smarty variable
- pass this variable to your UDT

3:
- use CGSimpleSmarty for retrive content and assign
- pass this variable to your UDT

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

Re: Get and replace content_page before sending to browser with UDT

Post by calguy1000 »

No, the best way to do it is to have a UDT that handles the ContentPostRender event.  I think this could do it.
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.
Sonya

Re: Get and replace content_page before sending to browser with UDT

Post by Sonya »

alby wrote: - create a modifier smarty (view smarty doc)
Thank you. I've created modifier.link.php in /plugins directory of my project:

Code: Select all

function smarty_cms_modifier_link($string)
{
    return str_replace('word','<a href="#">word</a>',$string);
}
Then use the content tag in my theme with modifier:

Code: Select all

{content|link}
It works :)
Sonya

Re: Get and replace content_page before sending to browser with UDT

Post by Sonya »

calguy1000 wrote: No, the best way to do it is to have a UDT that handles the ContentPostRender event.  I think this could do it.
calguy100, I can assign UTD to event. But how can I handle an event with UDT?
Post Reply

Return to “Developers Discussion”