Jump to content

Setting up ids or a unique variable for a gallery


pers0n
 Share

Recommended Posts

New to processwire, looks amazing. Found out about it at the beginning of the month and am now playing with it, so forgive my ignorance.

I'm wanting to setup a gallery that belongs specifically to a different user page, because of that, I'm thinking I need a unique variable to tie the two together. I suppose I could put in a integer or textfield string for each user template, but then the user has to remember this, unless I "slugify" the title of the gallery, but they would still have to type it in fairly close to what it is. I notice processwire doesnt' have a selection box or auto tag pull in feature or anything like Drupal (a CMS I loathe) has.

Example:

USERPAGE TEMPLATE

title: Bubba

body: blah blah...

tag? (easy example would be to slugify GALLERYTITLE, so "flower-gallery"): flower-gallery

GALLERY TEMPLATE

title: Flower Gallery

body: Gallery of flowers...

images: (uploads of images)

Another alternative, would be to slugify the userpage into each Gallery instead, but that doesnt seem any better. A third alternative is to put a variable into both templates that has to match, possibly a integer or string, then the two would have to match up.

Perhaps I'm just overthinking this, let me know if someone has a better idea to do this.

Link to comment
Share on other sites

Hi pers0n and welcome to forums,

just use PageField type, which works as pointer to single/multiple pages. First create gallery, and then add it to your userpage via the PageField type.

Depending on your settings, you can select different methods of input, but I'm gonna let you find this out now.

Link to comment
Share on other sites

Thanks. I did as you said.

When I created the gallery, I set a field called userpage and had it set to the "page" type.

Now in the template I've tried to call both

$page->children;
$userpage->children;

Neither variable is giving me anything back though.

Link to comment
Share on other sites

Hi and welcome to PW forum!

since it's a field on the page, you get the selected page reference using something like this

<?php

/* make sure the inputfield i.e: "userpage" setting is set to allow only 1 page */

// get selected userpage url
echo $page->userpage->url;

/* if inputfield page is set to allow multiple selected */

// to get first
echo $page->userpage->first()->url; 

// to get all
foreach($page->userpage as $userpage){
    echo $userpage->url;
}

Written in the browser, so could contain errors.

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