Jump to content

Using placeholder in textfield (ckeditor)


tires
 Share

Recommended Posts

Hello!

I wonder if i can use some kind of placeholder for page-fields in a textarea (in this case with ckeditor)?

The plan is, to put some text/code in a textfield that looks like this:

<div>
<p> 
The headline of the parent page is: <?php  echo $pages->get("/somepage/")->theheadline; ?>
The headline of this page is: <?php echo $page->theheadline; ?>
</p> 
</div>

Is there a way to do so?

Or a do i have to install a additional module?

Many thanks and best regards

Link to comment
Share on other sites

I'm not fully understand what you want to do with your pagefield. But I do think a simple str_replace can do alot what you want.

<?php

$placeholders = array();

// loop through your page field, and create an array with your replacements.
foreach ($page->multipages as $p) {
	// create dynamic keys => values, where the key is the url of a page
	$placeholders['{' . $p->url . '}'] = $p->theheadline;
}

// Here {/somepage/} will be replaced with the theheadline of the /somepages/ page
$body = 'Vestibulum id ligula {/somepage/} porta felis euismod semper. Morbi leo risus, porta ac consectetur ac,
	vestibulum at eros. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh,
	ut fermentum massa justo sit amet risus. Donec id elit non mi porta gravida at eget metus.
	Donec id elit non mi porta gravida at eget metus. Vestibulum id ligula porta felis euismod semper.';

echo str_replace(array_keys($placeholders), $placeholders, $body);
  • Like 1
Link to comment
Share on other sites

Yes! Hanna is exactly what i am looking for! :-)

The str_replace is also pretty cool!

I think the default templating way don't work in this special case.

Because i have a pretty long text that comes from a textarea an i want to add words in there. For example: everytime the word "ball" is mentioned i want to have a placeholder befor this word that adds the headline ("red" or "blue" or "yellow") field. So on the page the word is displayed as "red ball".

Thank you!!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...