23487 Posts in 18996 Topics by 2878 members
Page: 1 2
|Go to End||Next >|
9 April 2014 at 9:21am
I am trying to serve a custom template based on the URl. Lets say i have the following URL and Templates.
Template1 = ShowCase1.ss
Template2 = ShowCase2.ss
For URL1 i would like to render the page with template ShowCase1 and for URL2, I would like to render the page with template ShowCase2
So, irrespective of the URL pattern which may have Action/ID/OtherId, If the request has get parameter called "Version" i have to provide that version of the custom template.
So can anyone please help with solve this...really appreciate your help.
9 April 2014 at 6:25pm
should be able to use $this->request->getVar('version') in your controller to get the value. You could them look to use this in a switch statement to change the template rendering. You should also check to see if the variable exists before running through the switch and have a default template to render if nothing is supplied.
$version = $this->request->getVar('version');
. . .etc
Or something along those lines.
10 April 2014 at 11:53am
thanks for the reply camfindlay, sorry i should have framed my question properly. I have got the logic sorted. But i am struggling to understand where should i add this code to if i want this logic to work at a global leel.
I would like to get the process working on every controller available. I have already tried it on one of the test controllers init() function and it works fine. Not sure if this is the right place tough
so I need to add this at a certain place in the control flow of the request that gets applied to any controller available.
10 April 2014 at 4:15pm Last edited: 10 April 2014 5:40pm
Do you mean applied to every controller or do you mean every action inside a controller?
The action is what is rendered to a view, unless you perhaps set the variable in the ini() as a class variable like $this->template and them later in your actions use the variable to set the $this->renderWith().
Might be good to get more context around what you are doing. Can you post an example of your controller class? Use http://sspaste.com/ if it is a long example.
Here is a working example: http://sspaste.com/paste/show/53462bbdd8201
14 April 2014 at 12:16pm
Basically i am trying to do the split testing working for my site. the issue is there are various page types in my site that are not listed in CMS so i cannot create a version of these un-listed pages. Lets say these page are called UnlistedA, UnlistedB and UnlistedC
These unlisted page types have actions within. So the idea was irrespective of the pagetype and action within the user is accessing if the URL has ?version=1 or 2 or 3 ....i have to render the data with that version of the template.
I did not want to repeat the checking of version code in every Controller. So was looking for a place so that it gets applied to every controller and every action within the controller.
Hope i managed to explain the scenario
14 April 2014 at 12:26pm
Did you check out the code I linked to about?
If you are talking about Page_Controller you could take my code and put in the Page_Controller init function.
14 April 2014 at 7:29pm
FYI, sspaste.com is dead with "Bandwidth Limit Exceeded"
15 April 2014 at 11:04am
That's no good ~ in that case I have made a gist for you to look at.
This is a custom ContentController but if you are referring to Page_Controller init you could most likely adapt it (I don't know the details of your project).
Page: 1 2
|Go to Top||Next >|