Recent Topics

1 Feb 16, 2008 17:17    

I need to render the permanent url in a plugin. But when rendered as html, it doesn't recognize the php call and just displays the code.

	function RenderItemAsHtml( & $params )
$params['data'] = $params['data']."<br />".$this->Settings->get( 'html_block' );
		return true;

Html_block contains: <?php $Item->get_permanent_url(); ?>

I presume I have to somehow tell the plugin that if it sees the words permanent_url in the html block to replace it with the $Item->get_permanent_url(). This is way beyond my ability... i am lost.

Any tips?

2 Feb 16, 2008 17:49

$params['data'] .= '<br />'.str_replace( '<?php $Item->get_permanent_url(); ?>', $params['Item']->get_permanent_url(), $this->Settings->get( 'html_block' ) );

or summat like that, but you're better off using place holders :

[html block]foo = <a href="$item_url$">bar</a>[/html block]

and then just replace $item_url$ ;)


3 Feb 16, 2008 20:50

¥åßßå, as always you are a great help here.

My knowledge is very limited... but I don't think I can use placeholders for this particular idea.... anyhoo

So do I understand this code... that if it sees get_permanent_url it will render and replace it with the the permalink by using the php code?

$params['data'] .= '<br />'.str_replace( '<?php $Item->get_permanent_url(); ?>', $params['Item']->get_permanent_url(), $this->Settings->get( 'html_block' ) ); 

so the html in the html block would be?
<a href="$item_get_permanent_url$">bar</a>

I must be doing something wrong... which isn't really surprising... cause I really have no idea what I am doing... LOL

4 Feb 17, 2008 10:56

See if this helps clarify

html_block wrote:

'defaultvalue' => '
<!-- Paste from here... -->
example of some html for the permalink <a href="$permanent_url$">$title$</a>
<!-- here -->

    * Event handler: Called when rendering item/post contents as HTML. (CACHED)
   function RenderItemAsHtml( & $params )
   	// I'm lazy and this is less typing in replace array ;)
   	$Item = $params['Item'];

   	// list of all placeholders
   	$search = array( '$permanent_url$', '$title$' );

		// list of placeholder replacements, must be in the same order as search
		$replace = array( $Item->get_permanent_url(), $Item->title );

		// replace placeholders with their values
		$params['data'] .= '<br />'.str_replace( $search, $replace, $this->Settings->get( 'html_block' ) );

		return true;


5 Feb 17, 2008 15:31

That looks fantastic... so it pains me to tell you that it didn't work, nothing is rendered, not even plain text. ... not sure why. where should I go from here?

thanx for your help....

7 Feb 17, 2008 16:52

did I mention I was a blonde too... that again is another great piece of coding ¥åßßå! Beautiful! I hope to get this plugin up and running soon! Thanks for your help!!

8 Feb 17, 2008 23:59

The world needs far more blondes :D


9 Feb 18, 2008 00:01

Please do
$Item = & $params['Item'];
instead of
$Item = $params['Item'];

The latter won't work in PHP4 and the first one is more explicit anyway (assigning by reference).

10 Feb 18, 2008 00:18

Is that important if all we need is to get info from $Item, as opposed to changing any of $Item's data ?


11 Feb 22, 2008 20:58

No, ¥åßßå, when you only get data it's not really important if it's a reference or a copy.
Sorry for the confusion.. ;)

Form is loading...