Yii Page Variation - php

I have a website that needs to have a variation of pages.
For example:
website.com/variation1/page1
website.com/variation2/page1
website.com/variation3/page1
All of which has the same DB and has the same function. The only difference is that these variations differs in page template ie. Header, Footer, Content, etc. This is for the purpose of analyzing page visits.
With that, what is the best way to do this? In Yii, there is a common layout used so header/footer depends on the layout. In this case, the header/footer should be specific to each page so the user can just modify the header/footer/content of a specific page without affecting other pages.
So, again what is the best approach for this?
Thank you in advance.
EDIT:
I think I know what I'm looking for here:
Is there a way to override/add from a layout the header in a view file?

Create Three different layouts say variation1.php, variation2.php, variation3.php, then based on the action(website.com/variation/pageone) or the parameter(website.com/variation/page/1) change the layout(in action).

I just found out a possible solution to approach page variations.
Under my view directory I created a directory varation which contains the pages i.e.
/view/variation/1/page1.php
/view/variation/2/page1.php
So when I want to render the varations I'll call each in the controller with parameters included.
Ex. $this->render('variation/1/page1') somewhat.
And in each page if you want to use a specific header info you may use
Register Meta Tag
Register Script File / Script
Register CSS File / CSS
Let me know if there are better ways of doing this.

Related

Dynamic websites using php without inclusion

I am developing a website where all 5 main pages(home, about me, contact, blog, my foundation) are structured different from each other so I dont want to use the include() function to inherit anything from the index. how do I go about going to these pages about me (home, about me, contact, blog, my foundation)
You will need to add a link from each page to every page. It would be best to create a header.php file which you would include on every page. This file would contain your 'navigation' or the links to all the other pages. Since you say you don't want to use includes you will have to add this same code at the top of all the pages. If you want to change them you will have to change them on every page. If you used the include() function instead you would only have to change it once.

Modifying the variables in .tpl files in drupal

I know that this is bit of a conceptual question but after searching alot i am unable to grab the concept that is why i am hoping to get help from this platform.
I often need to change some markup or styles etc on the elements let se in $page['highlight']
When i var_dump any variable in any .tpl file it gives just a basic information. Let say i have to add additional div element in a content that is set to be rendered in $page['highlight'] region. What would be the way that i grab that element and alter it before it rendered on page.
The same case happend to me when i made a page view in drupal. I had a custom .tpl file which was displaying the view and all records were getting displayed by a single variable like
print $rows
I am not specifically asking for the code but it would be helpful to many other users including me to grab the concept with a little example.
Thanks alot.
There are different ways to do the same things you say.
In views, you can customize your results by Theme: information option. Is's in the bottom-right part of the view configuration. Here you have the option to create a new file and customize the view results. In your case you need to create a new Row style output: (it contains the value of $row variable).
Here is a tutorial: https://www.ostraining.com/blog/drupal/views-templates/
About the $page variable. You have different options depends on the context. For example if you need to add a in all pages, the best option is to edit the page.tpl.php in your theme.
Another option is to change the template.php of your theme, but only if you need to add html in some cases.
Hope it helps.
Regards.

Passing Stylesheet to View from Controller

Is it possible to pass a Stylesheet to a view from a controller?
I have a master.layout file. This master layout is used for every page on the site. On the site the user can change colors and properties of their user profile, so on the profile pages I need to pass in either a custom user stylesheet, or custom style rules.
The only solution I have found is to include an if statement in the view and if the page is a profile page then check if $style is defined, if so include it. But this approach seems clunky.
Is it possible to define the layout and pass in scripts or style rules from within the controller itself?
Edit:
The style rules are stored in a database in columns such as profile.background_color and profile.heading_color. The controller then constructs them into either a stylesheet, and caches it, or includes the styles directly within a <style> tag on the profile view. I havn't decided which way to do it yet, but both are possible.
The advice about Facade was weird. That doens't really help you here.
You'll want to do a few things.
In your pages controller you can add:
$layout->with('extra_stylesheets', ['pages/someslug.css']);
Then that .css file should be processed as PHP using a little mod_rewrite and htaccess fun so it can be cached heavily (use more .htaccess for this, Google will help).
The layout then is the only location that needs to check for extra stylesheets and your pages view has a little less logic in it and your output HTML doesn't have a bunch of nasty <style> tags.
In master.layout, ensure you have a #section('userStyle')...#stop or similar.
In your controller, set the property protected $layout = 'master.layout';.
Build out the css as you are currently doing and store it in a php variable $css.
Then you can load up the css into your layout with $this->layout->userStyle = $css.

Change the URL also when changing the content of DIV with JQuery?

I want to achieve something like Facebook, where the top bar stays there and only the content underneath it changes for different pages. At the same time the URL at the top also changes, for example /messages or /events.
I'm not completely sure if this is how Facebook works but I'm trying to achieve something like this... Right now I can't figure out how this could be done...
Does anyone know how this could be achieved or if there is a name for it?
You could do this with a fixed header that is on all of your current pages, so that whenever a new page loads it appears the header is still there, or you could do the more complex way of putting all your pages in separate divs on one page, and hiding/showing the appropriate divs when a link is clicked. I'd recommend the first way personally, but those are some options.
I'm sure there are other ways to go about this.
If that isn't what you want then I apologize.
Edit: Also, my first suggestion will load a whole new page, so if you want the seamless transition effect then the second option will be the better route to go
Templates perhaps? You can't change urls without navigating to a different page as far as I know. If you want consistent elements on the page with varying content that basically is the function of templates.
If you're looking for dynamic elements to show up on the page then you should look into AJAX and DOM manipulation. jQuery is the defacto library to help with both of those. Take a look at http://api.jquery.com/ and maybe search for a template engine. Most web frameworks include a template system to create consistent styles and allow code reuse.
You can use #anchors, that won't reload the page. For newer browsers, you can use https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Manipulating_the_browser_history to update the url without reloading the page

Test custom header in Drupal before publishing

I'm quite new to Drupal and want do some editing of the header. I want a custom toolbar to appear on every page. I've already created that toolbar in a file called toolbar.php. It has a layer which is fixed and will appear on top of every page.
How do I include the toolbar.php in the header template of drupal?
The toolbar refers to $user which is a global Drupal variable and I want to test toolbar.php before publishing it to the site. Is there anyway I can do that?
Regards,
Dasith
Of the two methods above the first is easier if you understand the basic idea of html and CMS templates, the second will be easier if you are a programmer.
First thing to check is that you really need to do this! Can't you restyle one of the existing menus (Primary or secondary) to do this - will make your life (and anyone who works on the site in the future) a lot easier.
The other thing you can do is look into adding an output region, basically something where you put the php into a drupal friendly format and then effectively do a 'drupal print'. This is how the toolbar, search box etc are done. You still need to alter the templates as above.
Yes for sure. If you want to have the html produced by your function/file appear on every page of the site then you will need to over-ride the page.tpl.php file in the theme you are using and essentually add the html to that file.
To gain access to the $user variable, just declare it in your script.
global $user;
open page.tpl.php file in a code editor and save as page-front.tpl.php (with two dashes if you are using Drupal 7.. one dash with Drupal 6) and upload it to your theme's directory. Clear your cache by going to configuration->Performance->Clear All Cache. Then referesh the page. Now your homepage is using page-front.tpl.php as it's template file. Every page will need its own template file. The page machine name comes after the hyphen so the user page template uses page-user.tpl.php. You can edit it as you want. The proper way to really do this is to use hook_theme() to pass variables to the template file. One variable could be the html which creates your custom header.
See also http://drupal.org/node/457740 Beginners Guide to over riding theme output

Categories