Dynamic templates in Django - django

I'm about to make a dynamic website in Django so that user can change the template the website is based upon....for new users, they'll have to choose a template they like from a menu, after which this is stored in a cookie for future reference. I however don't know how to do this....any ideas.

Templates are text files in a directory on your server.
The menu is a list of directories.
The specific template to be loaded is named in your render_to_response calls in each view function.
It's wonderfully quite simple and elegant.
You never need to do a template "swap". You can simply have all the templates you ever want in a template search path. All can be available to all users at all times. You just provide directory_name/template_name. All handled for you.
Don't mess with explicit cookies. Django already does this for you. See chapter 12 of the Django Book.
Use the Profiles extension and put the selected template directory name in the user's profile.

When user selects a template, store the template name/ some sort of alias in the cookie. When the user loads the page again, in the view function, check for template identifier in the cookie. If the identifier is present, retrieve the actual template path and pass it to the render_to_response function.

Related

Kentico 10 Link to existing page feature

Is there any way to force Kentico 10 to adopt a certain template when I link to another page with a template of a type I do not want?
An example would be I have a folder of CTA's. I want one of these CTA's to link to a page that uses the template "genericTemplate" but I would like the linked page I just created to be of template type "nonGenericTemplate".
The reason for this is that "genericTemplate" does not have the fields I am looking for and I would prefer to not force people to input field data in two places ("genericTemplate" and "nonGenericTemplate")
I maybe misunderstanding what you mean by CTA; to me it's a link that a user can click on.
I don't believe that Kentico puts the field on the Page Template object, but on the Page Type object. The Page Type reflects what can be stored against a page, the Page Template reflects how the page looks.
When you create pages in Kentico you can assign a default Page Template to a Page Type in the administration interface; it's in the New document settings category of the Page Type interface called Default page template
If it's Page Type you meant, you can change the administration interface itself to only display fields when certain criteria are met. You could write a macro too, if the logic is quite complex. You can do this against a field itself or if you've got linked classes you can do it against the whole group. That way, you'd only need one Page Type to cover all eventualities.
John

Customize single-product template

I created my own template named ibtheme, then I copy woocommerce folder from Woocommerce plugin to my template. But when I click on a product on frontpage, I see that it call the template files in plugins/woocommerce/templates/single-product, not from ibtheme/woocommerce/templates/single-product/
Please help me to override product page template!
Thanks advance!
As you have already discovered, you can edit the template files in an upgrade safe way through overrides. Simply copy it into a directory within your theme named /woocommerce, keeping the same file structure.
Example: To overide the price display template, copy: wp-content/plugins/woocommerce/templates/single-product/price.php to wp-content/themes/ibtheme/woocommerce/single-product/price.php
You can read the full documentation for WooCommerce theming at Template Structure + overriding templates via a theme
I would suggest that only copy/override the specific templates that you plan to modify. I've had to go through every single template to repair a broken theme/site after a major WooCommerce upgrade, so trust me, this will make it easier to upgrade WooCommerce in the future.

Changing django extended template to have all provided templates according to my design

To utilize django's own provided templates like forgot password, change password and such templates and views funcionality, I made my own templates for login e.t.c. But after some time I found that there are many views and templates already present that one can utilize just by providing right URL but only problem is that these templates are extending django's own template. So I want to know that is there a way to only set extended template of my own choice that is my site's main template so that I just give the URL of forgot password or change password e.t.c. related pages and django render the template by extending my main template instead of django's own template. I am not sure if admin panel is extending the same template that other pages are.
Please tell how can I do so and also please tell if doing so can have any problem.
More detail:
I know inheritance and extending with our template file but how can I set my own template in such way that they automatically inherit mine.
For example, for forgotpassword, I had to make a template file and need to paste form elements and top of it I write {%extends main.html%} but I don't want that, I know that default forgot password template is being inherited from some default django template I want to set it some so that it always inherit from my template in that case.
Short answer: You have to write your own templates.
Longer answer:
Django does include some templates, but these are all intended solely for the admin application. The auth views default to using 'registration/some_template.html', and those templates all live in the admin app ( see https://github.com/django/django/tree/master/django/contrib/admin/templates/registration). The auth views all support a template keyword argument that you can supply in your URLConf, so that you can specify which of your own templates to use.
Think of the admin templates as a reference that you can use when writing your own templates, but not as something you're meant to use directly.
Try to get your head around template inheritance. I think you can achieve what you want using template inheritance. This is a good post introducing the topic.

Dynamically choose which base template to extend in django

I have content that is going to be the exact same between the mobile and web site. The only thing i want to change is the base template. One base template for the mobile HTML, and one for the website HTML.
One solution is to wrap the render_to_response and determine which HTML to render, but I'd still have two files.
Is there a way I can dynamically tell the template which page to extend?
Sure, you can just use a template variable as the template name. Try it out! :-)

Joomla Template Overrides

In joomla, I need to assign specially designed templates for both "User Edit" (Where user edits their details)
/index.php?option=com_user&view=user&task=edit
and "Search Results"
I can't for the life of me work out how Joomla is selecting templates now. Certainly ItemID's aren't obvious and template overrides aren't giving any clues.
Currently Search is defaulting to the site 'home page' template, and the user edit to the 'default' template.
I don't think it should matter but we are using jfusion.
Can anyone point me in the write direction
Thanks
Stephen
Templates in Joomla are assigned to different pages (via menu items) under Extensions > Template manager. The default template (with a star) is assigned to all otherwise unassigned pages. For the other templates, click the name and choose the pagesto assign it to.
If you don't have menu items assigned to the pages you mentioned, you can create a new menu called "hidden menu", make the menu items there, then link to those menus.
I think you're getting terminology mixed up though. "Template overrides" are files that reside in each template that override the default content output. There's only one set per template - if you want multiple template overrides you need multiple templates.
template over rides are stored in the templates folder.
so if you are using teh template called "beez" (comes stock standard)
the template overides are in :
templates/beez/html/
they are then stored under the module or component name. eg the article layout for com_content is stored in:
templates/beez/html/com_content/article/default.php
the template is usualy called default.php, but each component and module can have a few extra templates that they use as well as deafult.php
Now you are asking to change the "user" view for com_user when editing
I think that location is:
templates/beez/html/com_user/user/form.php
if you ever want to find the origanal template which is to be overridden in this case: template that would be in:
/components/com_user/views/user/tmpl/form.php
so in general
templates/templatename/component_name/view_name/template_filename.php
Lets try ::
/index.php?option=com_user&view=user&task=edit&template=template-name
parameter template comes from /includes/application.php:311
// Allows for overriding the active
template from the request
$template = JRequest::getCmd('template',
$template);
Hope it will work :-)