Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template replace #8530

Closed

Conversation

andrepereiradasilva
Copy link
Contributor

Description

This PR adds regexReplaceInTemplate function to JDocumentHTML

This can be used for adding/replacing html in the current template, like, for instance, adding HTML5 data-* attributes used by javascript.

Examples of usage:

JFactory::getDocument()->regexReplaceInTemplate('<body', '<body data-json=\''.json_encode(array('item1' => 'value1', 'item2' => 'value2')).'\'');
JFactory::getDocument()->regexReplaceInTemplate('<body', '<body data-var="1"');

Of course, since is a regex replace of the template HTML this can be used for many other things before the final html is rendered.

How to test

  1. Add one of the examples above somewhere in /libraries/cms/html/behaviour.php. I added in the caption function.
  2. Go to homepage and check if in the HTML code there is the following code:
    <body data-json='{"item1":"value1","item2":"value2"}'

B/C

None

@andrepereiradasilva
Copy link
Contributor Author

this doen't work on admin template so i will close it and try another way.

@andrepereiradasilva andrepereiradasilva deleted the template-replace branch November 25, 2015 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants