Jump to content

Repeater field with page field


Joss
 Share

Recommended Posts

I have a repeater field called block_footer_boxes_repeater

Within the repeater are two fields:

block_span, which is a simple text field

block_select which is a page field.

The page field is for selecting a single page which has a pile a fields in it. For the sake of this argument I will use just one: block_textarea_body

So here is my very simplified code (the proper code is a lot longer because of lots of fields and ifs, maybes and the odd but!)

$footblocks = $pages->get("/settings/footer-settings/")->block_footer_boxes_repeater;

foreach($footblocks as $footblock) {

echo $footblock->block_span;
echo $footblock->block_select->block_textarea_body;

}

The span is working fine.

The block_textarea_body is not.

I have also tried:

echo $footblock->block_textarea_body;

But that doesn't work either.

Just to emphasise that the page field is only selecting one page at a time (and is set to the single select option), so it is not an array.

Umm ...

That is about it. Kind of stuck now!

Joss

Link to comment
Share on other sites

Okay, I think the problem is two fold

Firstly, I have an background colour as one of my fields, and I seem to remember that the color selector doesn't work with repeater fields (actually, I may be misremembering that) - it just so happens that that was the field I was testing.

I am getting an image problem too.

So I think what is happening is that it is getting broken before it can output the data.

I have just got the title to work.

Link to comment
Share on other sites

Update

Okay, I have it all working now (my original code was fine)

But, I am not getting the colorpicker field. 

The value is in the database, but I cannot return it to save my life.

Any one had a problem with this before?

Link to comment
Share on other sites

I have now changed the way I am working.

I have decided to create a series of "themes" rather than allow any colour to be picked.

This does mean that I now have -

  • A Template to create pages for the theme selector
  • A page field in a Blocks template to select the theme
  • A page field in a Repeater field to select the block
  • And the repeater field in my Footer settings template.

At the moment (and leaving out the foreach loop) to get the data I have

$pages->get("/settings/footer-settings/")->block_footer_boxes_repeater->block_select->block_theme_select->block_class

Is there an easier way to get there?

:lol:

Link to comment
Share on other sites

Hi Soma - I wasn't totally sure it was a problem or whether I was doing something idiotic.

And I had a vague memory that we had this conversation a couple of months ago :)

Yeah I remember that there was something with the colorpicker, and I forgot it even you send me a personal message.

But it's always better to stick as much as possible to some thread topic, as it could make it easier to search for them. So many great hidden infos get lost because it's in a unrelated thread. :)

I have now changed the way I am working.

I have decided to create a series of "themes" rather than allow any colour to be picked.

This does mean that I now have -

  • A Template to create pages for the theme selector
  • A page field in a Blocks template to select the theme
  • A page field in a Repeater field to select the block
  • And the repeater field in my Footer settings template.

At the moment (and leaving out the foreach loop) to get the data I have

$pages->get("/settings/footer-settings/")->block_footer_boxes_repeater->block_select->block_theme_select->block_class

Is there an easier way to get there?

:lol:

My head just exploded. :D Seriously

Link to comment
Share on other sites

It works though!

I am not sure I would want to write out the Squirrel - not so much left joins as double jointed...

To be fair, there is a good reason for this.

The idea is that you can select multiple blocks from a library of blocks and set their spans individually - the added span factor is why it had to be repeater.

I suppose the really clever thing to do in the form would be to have all the text fields that take the span value linked so you had to make them all add up to 12 before you could save them. 

But I have no idea how to do that, and don't have time!

Link to comment
Share on other sites

One thing would be including a functions.php in your templates.


$footer_settings = "/settings/footer-settings/";
function getFooterTheme($p){     
    return wire("pages")->get($p)->block_footer_boxes_repeater->block_select->block_theme_select->block_class;
}

Then use it in templates with

echo getFooterTheme($footer_settings);
 
or

function getFooterTheme($p){
    return wire("pages")->get($p)->block_footer_boxes_repeater->block_select->block_theme_select;
}
and use it like this
echo getFooterTheme($footer_settings)->block_class;

I'm not sure what your needs are but if you see you're using a function or long call multiple times it makes sense to have a function or module that helps clean out your templates.

I don't think the chained call is too much, but you also have long names. But as you say image what it would take in any other System to get to the data in a call like this.

Link to comment
Share on other sites

hmm - I must have a head scratch over this. 

I do like being economical, however, because of my lack of knowledge, I have to make sure that when I look at it again in six months time I still understand it!

Thanks!

Link to comment
Share on other sites

Thaz where inline commenting comes in handy. You do it for that reason. Countless times I watched complex code I wrote years ago and takes me some time to understand it. Like wow I did that? Same with paintings btw.

Link to comment
Share on other sites

hehe

Yeah, I get that with music. I listen to something I wrote and produced and cannot for the life of me remember how I got "that" sound.

Trouble is, it was probably with some long dead keyboard or effects pedal.

Mind you, when it comes to commenting, sometimes I cant read the code for all my comments!

Link to comment
Share on other sites

Okay, getting it working properly now, with all kinds of variables.

This is what the fuss is about (not finished yet)

Basically, everything on the page (apart from the long text bit) is a block from a central library. The blocks can have different themes, videos, text, icons and so on. THings like titles can be swithed on and off.

For desktops, the blocks on each row are equalised in size (but that turns off for tablet and phones because it messes up)

blocks1.jpg

  • Like 2
Link to comment
Share on other sites

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...