简体   繁体   中英

Auto-populate site tree items for SilverStripe site

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!

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 (eg ShoppingCart).

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

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+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM