We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33344
    • 2 Posts
    Hi everyone,
    i’m new to modx so excuse my ignorance.

    My question is how to format the same document in different ways, supose i’ve made a document with text and an image. I’d like this document to be formatted in a different way if it appears on the "home page" (for example text on the left, image on the right resized) of my site and then have it in a different format in another page (for example image original size, text underneath)

    Are templates applied to a whole page or can a template be applied to document / a section of a page ?

    Is this possible?

    thanks
    zakary
      • 10746
      • 126 Posts
      Quote from: zakary at Jan 16, 2007, 06:05 AM

      Are templates applied to a whole page or can a template be applied to document / a section of a page ?

      A template describes the entire structure of a page, including the positioning of all the items, and contains a mixture of static HTML, and some MODx tags like [*pagetitle*], [*content*] and so on.

      Each individual page has a template assigned to it individually (obviously many pages can share the same template) and when that particular page is constructed, the tags are then replaced by the actual values relevant to that page .. so the [*pagetitle*] tag in the template gets replaced by the ACTUAL page title, and the [*content*] tag gets replaced by the actual content and so on.

      So you don’t really "apply a template" to a page ; its more that you "fill in a template" to make a page...

      In short, you can’t immediately do what you want using the normal MODx features.

      However, it may be possible to do this is some clever way, but I’m too new at MODx myself to see clearly how to do it .. the sort of thing that I am thinking of is a snippet that could "import" the data from a particular document. Then you could put the snippet into a second page (with a different template) and get the content re-formatted...

      Gordon
        • 33344
        • 2 Posts
        thanks for your reply gfroyle,
        i’m coming from etomite so i’m kind of familiar with templates, i just don’t know if i can (with default functionality of modx) do the different formatting on the same document.

        cheers
        zakary
          • 15987
          • 786 Posts
          there is the template switcher plugin that lets your users pick a different template to use. check it out here:

          http://modxcms.com/TemplateSwitcher-565.html
            • 14431
            • 65 Posts
            Quote from: zakary at Jan 16, 2007, 06:05 AM

            <snip>supose i’ve made a document with text and an image. I’d like this document to be formatted in a different way if it appears on the "home page" (for example text on the left, image on the right resized) of my site and then have it in a different format in another page (for example image original size, text underneath)
            </snip>
            thanks
            zakary

            Hi zakary,
            I’m new to modx as well so let’s hope the experts weigh in...
            What you are describing as a "document" sounds like it could be captured as what the folks around here call a "chunk" which is simply a piece of html markup. You could include <img id="anid" src="imgurl" alt="mypic" /> within the chunk to get the image. If you wrap your html "chunk" in a div, say <div id="mydoc">, then, you could include the same "chunk" on as many different pages as you wanted to. If you had created your templates (and associated css) for different pages so that the contents of a div with id=mydoc were rendered differently on different pages then it sounds like that would achieve what you described.
            Like I said, hopefully those who really know what they are talking about will confirm or correct.
            joe
              • 10746
              • 126 Posts
              Quote from: JoeP at Jan 16, 2007, 07:52 AM

              Like I said, hopefully those who really know what they are talking about will confirm or correct.
              joe

              This would certainly work if you had just one or two "special" pages that needed formatting differently in two separate places, but if there are many of them, then the number of chunks would blow out ..
                • 33372
                • 1,611 Posts
                I wouldn’t recommend you use the Template Switcher plugin for this. Unfortunately it breaks in 0.95 (badly). Plus it requires that you disable page caching, which is not ideal.

                I think that you may want to set this up using template variables (TVs) for additional content in the page (for example the image you mention, sidebar content, etc.). Then if you want this content to appear differently on another page (as opposed to on the same page, which is what the Template Switcher plugin does), just use a snippet to grab the first document’s content and TVs and output them however you like (with a different template). The MODx API makes it easy to access any data from any document and use it wherever you like.

                You could probably use Ditto for this without too much trouble, so check out that forum for ideas.
                  "Things are not what they appear to be; nor are they otherwise." - Buddha

                  "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                  Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                  • 7260
                  • 107 Posts
                  Chunks aside-(which are good too)

                  Unless Im totally off, I dont see why You can create a template for a particular section-
                  Lets Say Stories...

                  You start by copying your main template and then populate it with a few features an extra div or two etc.
                  and then you apply that template to that page as you publish it.

                  Then you can have a document that looks like the others but different.

                  (you can for instance use different Ids or classes on the alternate version of the template and have related styles for them in the style sheet. Thus modyfiying the look and feel of that section)

                  well..thats what Im messing around with right now anyways...Unfortunately I cant show you anything its just on a local box right now...

                  ZAP-yous solution sounds good too. If I run into trouble I guess that sounds like the thing to do...
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    There is also an "inherit template" plugin, so that all documents under a folder/container document will inherit its template.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 7260
                      • 107 Posts
                      inherit template plugin

                      is that already in the default install?

                      So...If I made a template for a folder..and selected it as the template for it...everything under that folder would inherit that template via a checkbox or something?

                      -ty