Posts by matdoidge

    I got this working with the information I was fetching and passing back in. I was very close initially. It ended up looking like:


    I was then able to use photos to inject the data into my album-detail template. Though after working this out, I realised what a pain it is to manage due Perch's inability to allow to set a related field as a column header in the admin panel so there is no easy way to view what album the photo belongs to. I've since opted for a single Collection as JayW mentioned.

    Why have two collections?


    Wouldn't it be better to have one collection called "Photo Albums" and within each album item, you'd have any number of images? I know this doesn't answer your question, but I'm curious as to how people are doing photos albums.

    To be honest, I am starting to think this might be the better option now. Either way it isn't particularly nice to manage but I might be able to use a repeater in a single collection and make my life easier.

    Maybe I've missed something but I think you might be overcomplicating this a bit.


    If you have a related field in your 'Album' collection you can use that related field in your template to fetch your 'Photo' collection items.


    That would be nice, but sadly albums are related to a photo, so when you're adding a photo you can select an album it goes into, That's why I can't just use related tags. I've managed to get the data back into the album but displaying it within a template seems to be a problem. My OP shows the output I get from <perch:showall> but that's only there because I'm passing it back in. For some reason I'm having trouble outputting that into the template.

    Hi guys,


    SO it's been a long time since I did a Perch build and I'm trying to create a gallery using two collections. One for the gallery 'album' and one for the 'photos'. At the moment I have albums as a related item of photos. At first I thought this made sense but upon building it out, it seems janky - I mean the whole thing isn't ideal as managing such a gallery is going to be far from nice.


    So I can make albums, assign a thumbnail etc. Then when I upload photos to the 'photos' collection, I can assign them to an album. The trouble I have is getting my head around setting this up correctly. I always get confused with related things in Perch and it's been a while...


    I have my albums collection listing output via a simple template, but when it comes to the details page can I fetch the photos that are related to the albums, because the logic is kind of the opposite way - albums are related to photos. So I am not sure using this logic that I can pull the photos I want that are related to my album. Hopefully some code will help demonstrate my ramblings:

    Updated code


    This outputs:


    It looks as if I am successfully getting the images back that belong to this album. From this data, how can I get these passed into my template for the album collection?

    Thanks Hussein,


    I ended up with something very similar although querying block type is a good idea, I shall implement that. Thanks as always

    I have a collection where the fields are setup inside of a item.html template file which contains just my fields and references a block template include.


    I am setting up a special template just for use on the homepage where I'll pull out some featured items and I wish to try get a specific title from a certain block - if it exists - is this possible from within the template without going to a page level and fetching it and injecting it back in to the template?

    You could use a single call and handle most of this within a single template. Perch offers ways of changing content for the first item (or a variety of arguments) - for instance:

    Code
    1. <perch:if exists="perch_item_first"> Your html for the first post </perch:if>

    You could then use this to template them all in a single file and avoid needing to remove the post from the first call. Pretty sure that's how I've handled similar situations in the past.

    Thank you for the comprehensive write up hussein. I’m having a play in order to fully get my head around it.


    If I just add the second collection to my callback, I can see location is being populated with ALL the items from within my location collection.


    I would then assume I can filter on it to only pullout the relevant location for each relationship. But if my locations collection has no reference to the shops collection, would i not struggle to ensure I’m only getting back the locations assigned to each shop?


    apologies if I’m still looking at this incorrectly.

    Thank you both. I've got it working using Hussein's suggestion of using a template... much easier. Although I do want to understand how the each function works - for future situations.


    Ellimondo, what is the value field doing in that example? Where you have - 'value' => $item['field key id name'], - what would that reference? This is my shop item, for example:


    HTML
    1. <perch:content id="name" type="text" label="Shop Name" required>
    2. <perch:content id="slug" type="slug" for="name">
    3. <perch:content id="logo" type="image" label="Shop Logo" divider-after="Opening Times" required>
    4. <perch:related id="location" collection="locations" max="1" scope-parent label="Select location">
    5. <perch:content id="uniqueid">
    6. </perch:related>
    7. <perch:content id="opening_times" type="textarea" label="Shop Opening Times" divider-after="Info" required>
    8. <perch:content id="info" type="textarea" label="Info" required>


    So:



    This isn't essential, I just want to try get my head around it so I can reference this in the future. Thanks guys.

    Hi Hussein,


    I thought as much. I literally been on this for an age now! I may just do as you said, as it could be a world easier to do this via a template. Out of curiosity, how would I access a specific field from the secondary collection? I've added a callback, which references the secondary collection, which pulls all of the fields through, but how would I filter for a specific field?


    Code
    1. $locations = perch_collection('Shops', [
    2. 'template' => 'shops/item_detail.html',
    3. 'skip-template' => true,
    4. 'return-html' => true,
    5. 'each' => function($item){
    6. $item['location'] = perch_collection('Locations', [
    7. ], true);
    8. return $item;
    9. },
    10. ]);

    Or would you it be tricky via this method?

    I am currently outputting a collection as JSON for consumption for a JavaScript app. It's all working as expected, but now I've hit a wall with related collection content.


    I have successfully enabled selection of one of the fields via a drop-down in my primary collection. But when I try to access that on one of my pages, I don't seem to be able to. How can I access this content from the related content for use in my JSON output?


    My JSON feed

    My line 'id'             => $location['location'], is not currently able to access this data. If I print the contents of $locations on another page, the content key looks like:


    Code
    1. [location] => Array ( [0] => 3 )


    My shop/item.html


    Code
    1. <perch:content id="name" type="text" label="Shop Name" required>
    2. <perch:content id="slug" type="slug" for="name">
    3. <perch:content id="logo" type="image" label="Shop Logo" divider-after="Opening Times" required>
    4. <perch:related id="location" collection="locations" max="1" label="Select location">
    5. <perch:content id="uniqueid">
    6. </perch:related>
    7. <perch:content id="opening_times" type="textarea" label="Shop Opening Times" divider-after="Info" required>
    8. <perch:content id="info" type="textarea" label="Info" required>




    I have found if I add a blog post, hit save, and it's set to publish. I then have to go into the meta tab, hit save, then go back to the edit story page, and hit save again - then my post wil appear... So that's three saves in order to get it to appear.

    As a site note, maybe the postIsPublished is irrelvant here, as removing the news set argument from perch_blog_custom makes them appear as I want. I could say that'll do, but if they make posts to the additional section, then they would appear here I think, which is why I was using the section argument.

    Hi Dunc,


    You are slightly correct, I am confused. It was a very long time ago I built this site, so I am tying to remember the logic. If I go into the meta, it's showing as the news section - however it's not appearing in my listing. And I'm unsure why it has a different ID in the database.


    From memory I use categories to split my news section out into two types and I have one more section which is no longer used. It seems to be the section causing me issues here as it's clearly not assigned the post to the section as it should be. I've checked all my test posts and they're all set to appear under the news section, but don't actually seem to be. Im curious why the ID suddenly changed in the database and why the postIsPublished is now appearing on new posts as zero, despite being clearly set to published on the admin screen.


    If I remove my set filter, they appear. I'm very confused!

    After some more digging I've narrowed down the problem...


    It appears as though new posts are not appearing under my 'news' section and instead appearing under a section that its' automatically created called 'posts'. I've tried going into blogs and setting 'category set' to 'news' but that didn't seem to change anything. I'm not sure why I can no longer get posts appearng under the section of news, and instead they're defaulting to posts.


    I have a category set called 'news' which I split into two sub categories - articles / athlete spotlight. Despite ticking the category when I make a new post, I don't think it's actually being properly assigned the category either. As when I filter in the admin by category, those new posts are no where to be found.


    Intesteringly if I look in the database I can see the the new posts but the final column labelled postIsPublished is at 0 and the sectionID is set to 1 where as older posts the postIsPublished is at 1 and the sectionID is set to 2.


    I have also run /perch/addons/apps/perch_blog/update/


    To confirm they are not appearing in the right section, if I modify my listing code, and remove the section option, I can see my posts:

    Code
    1. perch_blog_custom(array(
    2. 'section' => 'news',
    3. 'sort' => 'postDateTime',
    4. 'sort-order' => 'DESC',
    5. 'count' => 6,
    6. 'category' => array('news/articles/', 'news/athlete-spotlight/'),
    7. 'template' => 'news_listing.html',
    8. ));


    My blogs settings look like:


    4f3ab490590344021bc4985f1d3d0ac9-full.jpg

    Hi there,


    Today my client reported one of their image fields vanished from their 'athlete spotlight' post types. I logged in to take a look and sure enough the field was missing. I decided to delete and re-add the post to see if the field re-appeared (which it did). However the post never appeared on the website. Both the news listing page and the homepage - which pulls out the latest three - show nothing new. I've tried adding more posts under the other post types and it would appear now nothing I add is appearing. I've turned on debug and see no visible errors to explain why this is suddenly happening.


    I pull out stories on my listing page via:

    Code
    1. perch_blog_custom(array(
    2. 'template' => 'news_listing.html',
    3. 'count' => 6,
    4. 'section' => 'news',
    5. 'sort' => 'postDateTime',
    6. 'category' => array('news/articles/', 'news/athlete-spotlight/'),
    7. 'sort-order' => 'DESC',
    8. 'page-links' => true,
    9. ));

    My athlete spotlight post type template:

    I've not updated this site in 6 months and they've been posting fine since then. I really can't get my head around why it's stopped working.


    I am using Perch Runway: 3.0.4 and PHP: 7.1.32


    Debug after adding a new post:

    I have always wondered why I couldn't use a similar principle to creating regions via code. It always catches me out when I use standard Perch for ages then go to do a Runway site. I am quite sure I've even typed

    Code
    1. perch_collection_create

    before realizing my mistake.


    Programatically creating a collection would save a lot of work, for me at least.

    Obviously I don't know your structural layout but what I was trying to get at earlier was that at the moment you only have a small handful of rules in place. The trouble is your previous rule is being matched when you try go to the cart, therefore it's redirecting to the product page.


    Here is an example of a vanilla perch shop access file from an old project:

    You'll note how my shop product rewrites are near the bottom to avoid them being picked up and overruling the other rewrites. Now I am by no means an expert and this could well be a messy example, but hopefully it helps you.