Jump to content

Finding and posting repeater fields from another template


melissa_boyle
 Share

Recommended Posts

Hi Guys,

Basically I want to find a repeater field from the template "stockist" however I am finding this difficult to do so, I read this article on calling reapter fields as a template, can anyone help me on this, my code is as follows;

http://processwire.com/talk/topic/5029-search-specific-repeater-item-and-edit/

       <?php
       $results = $pages->find("template=repeater_store_left");
                
                    echo "<h5>{$results->store_name}</h5>";    
                    echo "<p class='less_padd'{$results->store_address}</p>";
            ?>
        </div>
 
Thanks Melissa
Link to comment
Share on other sites

That article is about finding a specific entry from inside a repeater field. If you want to find simply the repeater field of a page, you just have to do it as with any other field: $page->name_of_repeater_field. The difference is that this field returns an array (just like images, or page fields), so you will have to loop through it.

I don't understand exactly what you mean by finding the field by template. You want to find the repeater fields form all the pages that use the "stockist" template? Or you have only one page that uses that template?

Link to comment
Share on other sites

Awww right, silly me. Basically I need to find the template which is stockist with the stores_left repeater field but this doesn't seem to work for me. Do you have any idea?

Thanks,

Mel

 <?php
       $results = $pages->find("template=stockist");
 
                foreach($result->store_middle as $storesmiddle) {
                
                    echo "<h5>{$storesmiddle->store_name}</h5>";    
                    echo "<p class='less_padd'{$storesmiddle->store_address}</p>";
             }
Link to comment
Share on other sites

$results = $pages->find("template=stockist");

this will return an array of pages, so you would also have to also loop over it. But is that what you want? to get the repeater field of many pages?

Link to comment
Share on other sites

Stop me if I'm wrong, but does the stockist template only apply to one page? If that is the case, you need to create a stockist.php template file which will load when you browse to that page with something like the following code:

<?php
foreach ($page->store_middle as $store) {
    echo "<h5>$store->store_name</h5>";    
    echo "<p class='less_padd'>$store->store_address</p>";
}

However, if you have more than one page using the stockist template then something like this would work:

<?php
foreach ($pages->find("template=stockist") as $stockist) {
    foreach ($stockist->store_middle as $store) {
        echo "<h5>$store->store_name</h5>";    
        echo "<p class='less_padd'>$store->store_address</p>";
    }
}

What I have noticed is that you mentioned _left and _middle in your code, so that might be causing an issue too. You also hadn't closed your opening <p> tag which might be hiding some content perhaps?

Hope that helps.

  • Like 2
Link to comment
Share on other sites

Guys just a quickie,

Now that I have got the content across from another template I want it to only show the repeater field if an image is uploaded into a field with the repeater field named basket_icon. For example: it is a brand that stocks 2 products. I want to pull the stores that sell the products from the stockist page to the individual product pages. e.g. if product icon is uploaded into the basket_icon field then pull the store info to the basket page. This is what I have so far but it doesn't work:

<?php
foreach ($pages->find("template=stockist") as $stockist) {
    foreach ($stockist->store_left as $store) {
        if ($store->basket_icon) {
            echo "<h5>$store->store_name</h5>";    
               echo "<p class='less_padd'>$store->store_address</p>";
           }
    }
}            ?>
 
Thanks,
Melissa
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...