Magento -how are pages differentiated? - templates

I'm a little confused with the way Magento implements web pages, and I'm hoping someone here can help me out.
I've figured out how to adjust themes and templates, etc., but I'm wondering how I implement content with them.
There is a disconnect in my understanding of how to put content into a page. Is this done with the layout and template files, or is this done on the cms page?
I've been searching for tutorials, etc., and I'm having trouble finding them (maybe I'm using the wrong terminology), so if you know of examples or anything that might help, I would really appreciate it.
Thank you in advance for your help!

Magento design/template is a broad question, which may appears tricky at first, but so logical and powerfull once you get to know it.
In a nutshell, the .xml layout files are responsible for defining the content, and the phtml (in relation with their Block classes) actually render the html. Everytime a page load, all the layout files are parsed to retrieve all the blocks which have to appears in this particular page.
The content loaded in each page is defined by the handles in the layout files, which correspond to the module/controller/action. For example, the content of the customer's account index page (which is the result of the index action, of the Account Controller of the Customer module, see the logic of the handle's name) is defined by:
the blocks/layout defined in the <customer_account_index> handle of app/design/PACKAGE/TEMPLATE/layout/customer.xml
the blocks/layout defined in the <customer_account_index> handle of all other layout files (I'm not saying that all layout files have a <customer_account_index> handle, but those who have it, like poll.xml, will insert their content)
the blocks/layout defined in the <default> handle of all other layout files, that's why it's called "default" :)
When you say:
is this done on the cms page?
I assume you're refering to the cms in the admin: this only take care of the content block of the static pages of your store. And the rest of the page is still defined by the xml (the page.xml handle of the cms page's layout (1 column, 2 columns-left, etc...) handles like <default>, <cms_index_index>, etc...) But even there, you can modify the layout by putting content in the proper textareas.
Here are some interesting links to understand the magic of Magento's layout:
Demystifying Magento’s Layout XML
Magento for Developers: Part 4 - Magento Layouts, Blocks and Templatese
No Frills Magento Layout by Alan Storm
Designer's Guide to Magento
HTH

Related

Flexible block positioning in Django?

In Drupal you could choose in which "region" of your site you want your block displayed. You did not have to modify any php/html code in order to achieve this.
Can such a thing be achieved with Django, and if yes, how?
By block I understand a piece of html output that doesn't have it's own URL and gets displayed along side the main data. (for example a search box or a poll)
Hm you probably want to create context processor and just output from it where you want it in template?
If you want reordering of content blocks in html output inside admin then you need something to generate that output like cms. You could try something like django-fluent-contents for this without requiring big cms.
Django and Drupal shouldn't be compared like this: Drupal is a CMS, Django is a web framework.
If you want to get a somewhat similar experience, I would look at using django-cms. With this, you can create numerous templates and set placeholders within these templates (these are regions of the page like 'sidebar', 'footer', 'content area' etc.). When you go to create a new page in django-cms, you select which template you want to use (maybe a two column layout or a three column layout with a header - depending on what you have created) and then you choose what content (or plugins) you want to place within the placeholders you have created in the template. So this is a somewhat similar experience to Drupal's regions.

Editable unstructured pages

I'm building a small site framework for a set of sites that are likely to have quite a few unstructured pages - meaning they have:
Slightly different layouts per page
Lots of one-off text
None/very little generated content from models
I would like to allow clients to edit the content of these pages through my admin UI (I'm using Django for this project), but with the requirement that they are not exposed to the page HTML and are only able to edit parts of the page that I've specified as fields; for example:
Titles
A few blocks of text content
Perhaps some blocks of predefined image locations
PDF files that need embedding
Where these fields vary significantly between pages.
The layout, and what fields these pages require would be specified by the developer, so there's no need to dynamically generate much for this.
The 'best' idea I've had so far is to serialise these blocks of content once they've been edited by the user and store them in a 'Pages' table/model in my relational database, or just throw MongoDB or similar at it.
Conceptually, how would you implement such pages? As mentioned, I'm using Django so any implementation suggestions specific to Django are welcome, but general high-level ideas would be great too.
I would implement a ContentBlock model, which has .kind (header, text, image, pdf) and a .data, which would house the content (if text) or path to an uploaded pdf/image/etc. Presumably then you'd hardcode the pages with the appropriate blocks defined - I'd just use hardcoded slugs, eg, 'home-title', 'home-intro', 'about-title', 'about-text', 'about-right-photo', etc.
I would suggest not using Django's admin interface. It's much more suited to editing homogenous, non-business-logic models. I'd just add an edit view that renders the appropriate form fields for the blocks instead - html editor, file upload, etc. It's possible to do that in the django admin, but in my experience it's not worth the trouble - plus, if you do your own edit view, you can have it use the same base templates as the rest of the site, which IMO is a better user experience.
Here are a couple of apps which do that for you:
django-generic-flatblocks
django-boxes
Along with django-frontendadmin, it's super cool.

Include a page in the template script in magnolia cms

How can I include a page from magnolia into a magnolia template script?
In the template script with I can access data from a specific page, but how can I load that page into the template?
Let's say I have 2 pages each with its own template. Page 1 contains in its tree page 2. I want to include in the template script of page 1, page 2, but doesn't work.
Thank you very much :)
UPDATED
What I actually want to do is include my header in all of my project's pages. But I don't want to put it as a paragraph, because if I ever want to change my header, I'll have to edit all the project's pages.
So what I try to do and I don't know if this is the correct approach is to create a page template for the header. This template won't include any , or css, it's just the code for the header.
The next thing I want to do is create a page in magnolia with that model to be the header.
Next I'd like to include the page I've just created in my main template model for the project, but I can't figure how to do that.
I am new to Magnolia cms and initially I tried creating my demo site using stk. The only problem was that I couldn't use jsp as a scripting language, or at least I couldn't find any solution on the internet. I don't really know freemarker, but that's not really a big problem. I'm really reluctant in using freemarker because maybe in the future in a more complex project I might need some features that freemarker doesn't support, but jsp does. I'd like to build my site using jsp if that's possible with magnolia.
I'm sorry for this long update, but if anyone has any suggestions on what a best practice could be and if I could implement what I want in jsp I would be really grateful.
Thanks again for you time :)
If you're using the STK then see this guide on content-reuse.
If not have a look at the cms tag-lib, especially the tags cms:loadPage and cms:setNode with which you can get a piece of content and set it as a JSP/JSTL variable and then render it using cms:includeTemplate.
A common scenario is to 'inherit' content from the parent page, the header is an excellent example of this. What you do is for an area you walk up the content hierarchy and render everything from the parent pages in their area with the same name. This way the header which you've only added to the top page is included in all its children.
Another option is to a have special page which simply holds things to be included in other pages. Like header, footer and banners that should go in the side pane of some pages.
Including a page within another page doesn't really work. Page 2 already has its own <html> tags, its own <script> tags, and its own CSS, so including it wholesale into another page just simply doesn't make sense.
You do, however, have a couple of options:
Use an iframe. This will allow you to include the entirety of Page 2 in a region of Page 1.
More recent versions of Magnolia will allow you to render an individual paragraph, which you could then include in another page. (For example, you can see a single paragraph from http://demopublic.magnolia-cms.com/demo-project/about/subsection-articles.html at http://demopublic.magnolia-cms.com/demo-project/about/subsection-articles/article/main/0.html.) This requires knowing a bit about the way the data is structured, but is a pretty useful way to be able to selectively extracts bits of a page.
You can use the Magnolia API in your model class to pull data from sub-pages, and then make it available to your view template. This is the approach the STK uses to build teasers that include content from the pages they reference, and is probably the most powerful and flexible approach, but it does require actually writing some Java code. (See http://documentation.magnolia-cms.com/templating/stk/templating.html and http://documentation.magnolia-cms.com/reference/templating.html for details of how to use this approach.)
(Added after question was edited) The footer functionality that's included with the STK does almost exactly this. You might be interested to take a look at that and see how it's implemented there.
Hope that helps a bit!

Liferay 6 - How to set up custom layout as default?

I'm working on a Liferay 6 project, and part of the project is to create a new layout template to be used for the entire site as the default. Liferay's own wiki is very sparse on documentation about layout templates, and I haven't had better luck with Google searches or even here on SO.
I did find one article ( Liferay - Layout for each pages ) that sort of answers the question, but it seems like it might be overkill. In that question, the goal was to change the template based on the page, so the answer was to create a Hook and use that to set the template on the fly as needed. Here, I just want to have this custom template be the default for all pages, all the time, which is why I think the answer to that other question might be more than is really needed.
If anyone has the answer to this puzzler, please let me know. Thanks!
-- JLM --
OK, I've figured out my confusion. Liferay has two types of layout templates -- templates that are part of a theme, which is one type of Liferay project, as well as actual layout template projects themselves.
The templates in a theme are where you set up the overall page layout for the site. The main page template, named portal_normal.vm, is a full web page with an <html> tag, a <head> and <body>, etc. Other templates in the theme are usually page fragments.
A Layout Template, on the other hand, is only for laying out the portlets in the main content region of your page (which is defined by tags in your Theme's template files). It is always a fragment and can only have <div> elements or a <table> for laying out the portlets.
Fortunately, this actually makes answering my question very easy, at least in the context that I needed. Per Liferay's documentation at http://www.liferay.com/community/wiki/-/wiki/Main/How+To+Change+Liferay+Default+Theme :
Note: As of 6.x, you cannot just use the theme id specified in the liferay-look-and-feel.xml. Instead, go to Control Panel->Plugins Configuration->Click on theme of interest->note the Plugin ID and use that [as the value for default.theme.id in portal-ext.properties]
I hope this helps some other people trying to figure this out!

Using layouts/elements in Cakephp

I am developing a webapp using Cakephp. I have created a default layout for the website. I created sections like header, footer, content.
Now some of the pages in my content section have same structure. These are part of a controller with various views defined for each page. What view template should I be using here? Layouts or Elements?
In case I use layout, I will be using the controller to decide the layout I will use, but won't that change the layout for whole website?
Regards
This is really a matter of preference. I try to think of layout as the "structure" of the page -- so a header, placeholder for left nav, placeholder for top nav, footer. That kind of thing. I define those sections in the layout.
I'd recommend the "pages in my content section [that] have the same structure" be your layout. As you mentioned, you can switch layouts in the controller, but any similarly structured pages (pages that will look the same as each other once you've removed the content) I would have share a layout.
Another example of layout switching could be for logged in versus anonymous users. For a logged in user, websites frequently put a "Welcome, $name" message at the top, along with links to My Account, sign out, etc. I often find myself using a different layout for logged in versus anon users. ALso, in that situation, I use the beforeFilter() method to set the layout for a given controller, since I know whether the user is logged in or not when that callback is executed.
Sorry for the rambling, but this is a bit of a gray area (when to use a layout versus different elements).