This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Johnathan Heath
Johnathan Heath

Hi, I'm currently having an issue with the repeater field variables on partials. I'm not entirely sure if it even works like that or if it has to be on a layout page only, I'm still figuring out how these field variables work. Currently I'm trying to make a list of contact numbers that are editable in the backend CMS on the static pages plugin. It works just fine when it's not a partial however when added to a partial it breaks completely just showing the field variable code on the website. Below is a linked screenshot of what the output looks like on a partial. You should also be able to see how the field variable code is inputted through the partial output screenshot. I'm wondering if maybe there is a step I missed I know when I use the menu's from static pages plugin I have to use some php code in the onStart function to grab the menu data. Do I need to do something similar for the field variables?

Non-partial output: https://tinyurl.com/y2e5upyb

Partial output: https://tinyurl.com/yxdyecd3

Last updated

mjauvin
mjauvin

Can you show the actual markup for both screenshots above?

Johnathan Heath
Johnathan Heath

In terms of code, yes I can as all the data is in the db. As it is an unlaunched site however I obviously can't release the actual details. I'll post screenshots of what the end result will look like with some fake numbers as well as a snippet of the repeater field code. This code is in a partial I have made in the partials/site/footer.htm file. It links to my homepage template as {% 'site/footer' %}, it loads everything in the footer correctly except for the repeater field data. This template is connected to the static pages plugin which I will also post a screenshot of just so you see the data fields are being read by OCMS when outside of the partial itself. This is the only bit of code relating to the contact field on the partial as I wasn't sure if I needed to use php code to connect to static pages like I did with the following. Forgive me if this ends up outputting incorrectly on the forums, not sure if this is the correct way to show markup of the code as I'm still pretty new to using the forums.

Outside of partial Pages data: https://tinyurl.com/yxqy69a4

Resulting output with fake data: https://tinyurl.com/yxool2nq

Repeater field code:


{repeater tab="Footer" name="footer_contact" prompt="Add another contact number."}
                    <ul class="footer-text">
                      <a href="{text name="contact_link" label="Contact Link" span="auto"}{/text}">
                        {text name="contact_location" label="Contact Location" span="auto"}{/text}
                        <p class="float-right">{text name="contact_number" label="Contact Number" span="auto"}{/text}</p>
                      </a>
                    </ul>
                  {/repeater}

Last updated

Johnathan Heath
Johnathan Heath

What I did for menu items unrelated to the contact links using the menu section in static pages:



[staticMenu]
code = "navMain"
==
<?php
function onStart(){
    $menuItems = $this->controller->findComponentByName('navMain')->menuItems();
}
?>
==
{% for item in navMain.menuItems %}
              {% if item.code == 'main' %}
                <li class="nav-item px-1 xl:px-2">
                  <a class="nav-link text-base" href="{{ item.url }}" aria-label="Go to {{ item.title }}">{{ item.title }}</a>
                </li>
              {% endif %}
            {% endfor %}
mjauvin
mjauvin

ref. https://octobertricks.com/tricks/custom-page-field-cheatsheet

so you could use:

<ul>
{% for repeaterItem in repeaterName %}
    <li><a href="{{ repeaterItem.url }}">{{ repeaterItem.title }}</a></li>
{% endfor %}
</ul>

or something similar.

Hope that helps.

Johnathan Heath
Johnathan Heath

Does this connect with the static pages plugin? Sorry I'm slightly confused, how does this for loop connect specifically with the variables inside of a repeater field? Am I creating that variable list through the repeater field and accessing it through the for loop? Will the content of the for loop still be easily editable in the pages plugin? Also I checked my previous message regarding code and for some odd reason the first line of code didn't appear in the repeater field code snippet. I have fixed that. Hope that makes things a bit clearer.

Last updated

Johnathan Heath
Johnathan Heath

The for loop itself does work it is clearly accessing the number of items in that specific array from my /content/static-pages/index.htm file, is there a way to maintain it's appearance on the static pages plugin such as below? (screenshot I sent previously just linking again for easy access) If so how do I go about doing that? This has been a great help so far and has helped me to understand things a bit better.

https://tinyurl.com/yxqy69a4

mjauvin
mjauvin

the repeater field DEFINITION and its USE in the layout are two seperate things but compliment each other.

Johnathan Heath
Johnathan Heath

I see, so how would I prevent it from showing up previously on the frontend of the website like it did previously when it outputted the code? Where would be the best place to define the repeater field?

The output previously mentioned:/ https://tinyurl.com/yxdyecd3

mjauvin
mjauvin

Is your layout used for both cms/Static pages?

Johnathan Heath
Johnathan Heath

Yes, that is correct. The code will be placed in a footer partial that will appear on both CMS and static pages.

mjauvin
mjauvin

I don't understant what you mean by: "how would I prevent it from showing up previously on the frontend of the website like it did previously".

Johnathan Heath
Johnathan Heath

Maybe I'm misunderstanding what you meant, but you're saying I can define it so that the static pages plugin still has the editable view and I can just call it using the for loop in this instance to use it elsewhere is what I'm taking from what you've said?

mjauvin
mjauvin

the repeater field DEFINITION is going to be shown when EDITING static pages, and the for loop in your footer will be DISPLAYING the repeater values on any page using the layout.

JenniferLopez
JenniferLopez

@Johnathan Heath

The syntax parser does not work inside partials, as these are rendered separate to the layout on the CMS side.

What you would need to do is define the repeater inside the layout for the page, and then pass the variable to the partial.

Note that if you're looking to populate data on a global basis (such as adding contact numbers into a footer that will be used across the site), you're better off adding a field to the theme configuration instead. See https://octobercms.com/docs/themes/development#customization

Last updated

1-15 of 15

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.