Forums / Install & configuration / How Can I access URI parameters in templates?

How Can I access URI parameters in templates?

Author Message

Adolfo Barragán

Wednesday 22 January 2003 1:03:43 am

I've created a new "ViewMode" and his URI has two new parameters (i.e.: content/view/frontpage/16//param1/param2)

I need access to parameters in .../templates/node/view/frontpage.tpl but $viewParameters only has "ViewMode", "NodeID" and "LanguageCode".

Where are "param1" and "param2"?

Thanks in advance
Adolfo Barragan

Karsten Jennissen

Wednesday 22 January 2003 3:46:53 am

> I've created a new "ViewMode" and his URI has two new
> parameters (i.e.:
> content/view/frontpage/16//param1/param2)
>
> I need access to parameters in
> .../templates/node/view/frontpage.tpl but $viewParameters
> only has "ViewMode", "NodeID" and "LanguageCode".
>
> Where are "param1" and "param2"?
>
> Thanks in advance
> Adolfo Barragan

Sorry, don't have an answer to this. But your approach sounds interesting. Would you like to share how you created the custom view mode? I am sure, that it's not too difficult and that other users can benefit from this.

I prepared a Wiki site. You just have to add a few sentences of description. :-)

http://ezwiki.blanko.info/index.php/3XHT_NewViewMode

Thanks in advance.
Karsten

Pawel Frukacz

Thursday 23 January 2003 11:45:26 am

Hello!
You should try to extract all params with code like this:
$Module =& $Params["Module"];
$viewParams = $Module->ViewParameters;

$viewParams is now an array contained all parameters
now you only have to hand over the array or extracted fields to your .tpl file with "setAttribute" function.
Hope this will help.

Adolfo Barragán

Friday 24 January 2003 9:20:02 am

> Hello!
> You should try to extract all params with code like this:
> $Module =& $Params["Module"];
> $viewParams = $Module->ViewParameters;
>
> $viewParams is now an array contained all parameters
> now you only have to hand over the array or extracted fields
> to your .tpl file with "setAttribute" function.
> Hope this will help.

I try this, but $viewParams has only the "oficial" parameters, i.e: "ViewMode", "NodeId" and "LanguageCode".

Can you show me an example of "setAttribute" function?

Thanks
Adolfo Barragán

Adolfo Barragán

Friday 24 January 2003 9:47:37 am

> > I've created a new "ViewMode" and his URI has two new
> > parameters (i.e.:
> > content/view/frontpage/16//param1/param2)
> > ...

> I prepared a Wiki site. You just have to add a few sentences
> of description. :-)
>
> http://ezwiki.blanko.info/index.php/3XHT_NewViewMode
>
> Thanks in advance.
> Karsten

I try your link, but I need login. I searh in pages and follow "sign in" but I received an error.

If you wish you can speak me at fatimamc@supercable.es

Regards
Adolfo Barragán

Pawel Frukacz

Friday 24 January 2003 11:27:44 am

Hi again!
Have you tried to modify line 75 in your /kernel/content/module.php file?
Try adding these new parameters to an array under key "params".
Bye and good luck

Pawel Frukacz

Friday 24 January 2003 11:28:40 am

Hi again!
Have you tried to modify line 75 in your /kernel/content/module.php file?
Try adding these new parameters to an array under key "params".
Of course if you created new view then you should modify suitable module.php file.
Bye and good luck

Adolfo Barragán

Friday 24 January 2003 10:32:07 pm

> Hi again!
> Have you tried to modify line 75 in your
> /kernel/content/module.php file?
> Try adding these new parameters to an array under key
> "params".

I made something similar but I don't sure what is the best solution.

I've modified kernel/content/view.php:
I've added a new variable $myParams = $Params['Parameters'] (around line 53), and (around line 150) I've added $tpl->setVariable( 'myParams', $myParams ).

Now, I have a cariable $myParams in my new template.

What do you think?

P.S.: Can do you see message http://developer.ez.no/forum/message/13750 ?

Thanks in advanced
Adolfo Barragán

Pawel Frukacz

Saturday 25 January 2003 3:23:06 pm

I think it's a good solution but I found better and more formal. Try to modify line 75 in /kernel/content/module.php:
"params" => array( "ViewMode", "NodeID", "LanguageCode", "Param1", "Param2" ),
now in /kernel/content/view.php you can access params from URI (eg. index.php/user/content/view/full/2//Hello/World) with $Params['Param1'] and $Params['Param2'].

As for the second problem I found out how to access
multidimensional array and I succeed only with sth like that:
assume you hand over to your tpl file array:
$ar = array ( array ( array("0"=>"day_num", "1"=>"object_id") ) );
to access your "object_id" param you need to write:
{let ar_0=$ar.0}{let ar_0_0=$ar_0.0}{let ar_0_0_1=$ar_0_0.1}
This is rather rare way to access array field, but I think you can now build loops taking advantage of the code I've written.

Take care,
Pawel Frukacz