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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 05:04:12
Script start
Timing: Jan 18 2025 05:04:12
Module start 'layout'
Timing: Jan 18 2025 05:04:12
Module start 'content'
Timing: Jan 18 2025 05:04:14
Module end 'content'
Timing: Jan 18 2025 05:04:14
Script end

Main resources:

Total runtime1.2467 sec
Peak memory usage4,096.0000 KB
Database Queries77

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0068 588.1641152.6563
Module start 'layout' 0.00680.0029 740.820339.5078
Module start 'content' 0.00971.2354 780.3281591.1094
Module end 'content' 1.24510.0016 1,371.437520.1094
Script end 1.2466  1,391.5469 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.2862160.0002
Check MTime0.00160.1255160.0001
Mysql Total
Database connection0.00160.126710.0016
Mysqli_queries1.176794.3891770.0153
Looping result0.00060.0503750.0000
Template Total1.214497.420.6072
Template load0.00210.165220.0010
Template processing1.212397.245220.6062
Template load and register function0.00020.015310.0002
states
state_id_array0.00090.075410.0009
state_identifier_array0.00150.121420.0008
Override
Cache load0.00190.15361020.0000
Sytem overhead
Fetch class attribute can translate value0.00090.068530.0003
Fetch class attribute name0.00110.086390.0001
XML
Image XML parsing0.00040.028230.0001
class_abstraction
Instantiating content class attribute0.00000.001290.0000
General
dbfile0.00070.0594100.0001
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
19content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
18content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 48
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs