We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16895
    • 87 Posts
    [I’m running Revolution beta 5]

    Hi, I’m having trouble working out how to create multiple content areas automatically.

    This is my ideal layout:


    I want the maintainer to be able to add as many blocks of content (an h2 plus a .box div), with custom headings and content, as they wish but without having to add in the <div class="box"> and </div> tags themselves.

    This is my current method. For every single block apart from the first I use checkbox TVs to choose whether an h2+.box should be displayed, then two more textarea TVs for the h2 and content of that block (each through an individual chunk). My template thus contains something like this:

    <div class="leftcol">
    [[*left_column_title]]
    <div class="box">
    [[*content]]
    </div>
    [[*Showleftblock]] // this is a checkbox which returns a chunk containing h2+.box
    </div>
    <div class="rightcol">
    [[*right_column_title]]
    <div class="box">
    [[*right_column_content]]
    </div>
    [[*Showrightblock]]
    </div>
    [[*Showbottomblock]]
    


    This is approximately what it looks like:



    The main and biggest problem with this arrangement is that it means a custom set of TVs and chunk has to be set up for as many blocks as someone might want to add (that would mean 9 TVs and 3 chunks for just 3 extra blocks of content). Other problems include that it is rather confusing for someone not technically inclined to work out what all the TVs do and that it’s hard to organise them. An ideal solution would have some kind of way of automatically outputting as many blocks as the person chooses on-the-fly, but I can’t see how this could be done. I’m sure it’s possible though, I’ve been very impressed with modx so far.

    Thanks,
    Ross

    ps Please ask for clarification if you want it; I imagine this post is as clear as mud. Hopefully if I manage to work out a way of doing this it will serve as a good reference for others like me in the future.
      • 5340
      • 1,624 Posts
      Use that document as a container and make all those regions in your website as children documents

      <h2> header defined in a TV</h2> can become the title of the document
      <p>content 1</p> will become the content of the new children documnet

      Map

      Landing page <- header 5 and content 5
      - First Div <- header 1 and content 1
      - Second Div <- header 2 and content 3
      .....

      I hope this is what you are looking for
        • 16895
        • 87 Posts
        I can see what you mean (I think), and having every block of content as its own document will probably work. However, how do I then specify in the container document ’Fetch and display child documents that meet x criteria and format them in y way’? (so that each child document is pulled in and displayed without its identity having to be manually coded into the container (is this even feasible?))

        Thanks for your help so far,
        Ross
          • 5340
          • 1,624 Posts
          You can use either GetField or Ditto snippets.

          Eg:
          [[GetField? &docid=`13` &field=`pagetitle`]] + [[GetField? &docid=`13` &field=`content`]]
          OR
          [[Ditto? &documents=`13,15` $tpl=`yourTpl` &display=`2`]]

          Syntax is not exact so you have to look at those snippets documentation.
            • 4172
            • 5,888 Posts
            You can use documents for each content area and use Ditto. For filtering the right documents you can use &documents, &parents or/and &filter. To change template from area to area you can have a TV for example ’dittoChunk’ and use a little snippet or phx-modfier in your ditto-tpl which gets the right chunk for displaying the area.

            see also:
            http://bruno.tattoocms.de/3.html (not done with ditto, but with bloX, but its the same concept)
            http://www.siebennull.com/xedit/demo.html
            http://modxcms.com/forums/index.php/topic,33985.msg206683.html
            http://modxcms.com/forums/index.php?topic=5993.0
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 16895
              • 87 Posts
              Thanks, I can now see how to do it. I’ll go and implement it in the next couple of days and see if I can make if work.
                • 16895
                • 87 Posts
                Ok, I’ve encountered a problem. I created a new template just for the content block children, and it has a TV called ’blocklocation’ which is a dropdown list set to left, right or beneath. (So that the maintainer can choose where the block displays on the container page).

                This is my Ditto call in the container document: [[Ditto? &parents=`[[*id]]` &tpl=`content_block` &filter=`blocklocation,left,1`]]

                Unfortunately, this produces this error message: Fatal error: Call to a member function get() on a non-object in C:\xampp\xampp\htdocs\modx\core\components\ditto\model\ditto\ditto.class.inc.php on line 797

                If you take out the &filter, the call works as expected, displaying all of the children content blocks. However, I only want to display ones that have blocklocation set to left in the left column, set to right in the right column etc. I have also tried getResources, but as soon as the &tvFilters is added nothing at all is returned.

                Any ideas?
                  • 3749
                  • 24,544 Posts
                  Do you have the latest versions of both Revo and Ditto?
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 16895
                    • 87 Posts
                    Yup, think so:
                    MODx Revolution 2.0.0-beta-5 rev6224
                    Ditto 3.0 alpha2 (although clicking the + the readme bit says 2.1.2; I assume this is because it’s an early port)
                      • 16895
                      • 87 Posts
                      Has there been a change to the TV architecture for Revo? I’ve now discovered that using the id in the filter works perfectly (of course this is no use to me because it would require customisation on every page). My test child documents are 15 and 17, and id,15,1 only displays 15 as expected, but as soon as you switch in blocklocation BAM! and it stops working. Even more confusing: if I change the variable name from id/blocklocation to a nonexistent variable such as ’foo’, the page again begins to display as normal, showing ’No documents found.’ as one would expect.

                      *head implodes*