4

I am still learning SilverStripe, and right now, I have a list of 50-60 pages I have to create for a site. It was suggested that I find a way to auto-populate the SilverStripe site tree with some code in order to save time (as opposed to manually creating each page one at a time). I have never tried something like this before (with or without a CMS). I know what the parent and child page names are, and I suppose I would need to create a loop to build out the child pages for each parent.

Is this something that is possible in SilverStripe? Would a for loop be the best approach or is there a more efficient way? If I can make creating these pages easier, it would be great for me for this project and future ones, so any advice would be appreciated!

wmk
  • 4,598
  • 1
  • 20
  • 37
Dejsa Cocan
  • 1,539
  • 3
  • 19
  • 56

3 Answers3

4

My understanding of this question is that you want to pre-populate the pages and their content programmatically rather than manually entering them in the CMS. There are a few projects that might help you.

  1. Populate module (https://github.com/dnadesign/silverstripe-populate)
  2. SilverSmith (https://github.com/unclecheese/SilverSmith)

Or you could simply override DataObject::requireDefaultRecords and build the pages out there. I would often use that method for functional or one-off type pages (e.g. ShoppingCart).

Mark Guinn
  • 619
  • 3
  • 8
  • silversmith is afaik 3.0 only, but populate module works great! just define a yml file and run the populate task. It's a great time saver – wmk Aug 11 '15 at 19:31
3

There is also a Site Tree Importer from SilverStrip Labs. It's hosted on Github

muskie9
  • 476
  • 2
  • 5
0

Yes, it's possible.

<ul>
<% loop $Menu(your id here) %>
    <li>
        <a href="$Link" class="$LinkingMode">$MenuTitle.XML</a>
        <% if $Children %>
        <ul>
        <% loop $Children %>
            <li>
                <a href="$Link" class="$LinkingMode">$MenuTitle.XML</a>
                <% if $Children %>
                <ul>
                <% loop $Children %>
                    <li>
                        <a href="$Link" class="$LinkingMode">$MenuTitle.XML</a>
                    </li>
                <% end_loop %>
                </ul>
                <% end_if %>
            </li>
        <% end_loop %>
        </ul>
        <% end_if %>
    </li>
<% end_loop %>
</ul>

Keep in mind that the code may differ a little and that this is for SilverStripe v3+

Stanimir Dimitrov
  • 1,872
  • 2
  • 20
  • 25
  • I like this idea (and it should work as I am using SilverStripe 3.1)! But how or where would this loop need to be placed in order for it to run? I'm guessing I would need it to run when doing a Dev/Build? And is the loop meant to run based on a text file with a list of of the site's nav links? – Dejsa Cocan Aug 11 '15 at 15:39
  • Include this in your SideBar.ss file and than include that file in your main Page.ss file. – Stanimir Dimitrov Aug 11 '15 at 15:41
  • I think this may not work for what I want to do...this should work in creating a navigation template, but I'm not sure if this will create the pages in the site tree in the SilverStripe CMS backend...What I want to do first is to auto-populate the site tree with the pages if that is possible. – Dejsa Cocan Aug 11 '15 at 15:47