Jump to content

Combining Page field with URL field


onjegolders
 Share

Recommended Posts

Hey guys, I was just wondering if there was any scope for combining a Page field with a URL field.

The circumstances are that I have certain blocks in a sidebar and the user can choose to link them either to an internal page or to an external url.

I'm pretty sure that this is feasible from within TinyMCE but not sure how to approach it from normal page fields.

The user could copy/paste in an internal link but I was wondering if there was any possibility of a future field where a user can choose either a page or a URL?

Link to comment
Share on other sites

I don't know if something like this is on the way, but I see two possible solutions.

One is to have a text field that would serve for both (but you wouldn't have the url check ability, nor the page select interface) and do something like in the template or a process module:

$link = is_numeric ($page->field) ? $pages->get($page->field)->url : $page->field;

The other is to have both fields, page and ulr, on the template (maybe grouped under a fieldset) and write that only one will be used. On the template you would have something like:

$link = $page->pagefield->url || $page->urlfield;
  • Like 1
Link to comment
Share on other sites

Thanks Dave, it needs to be a simple field if possible but the Hanna codes do look interesting (possible duplication with Nico's shortcodes?)

Thanks Diogo, I think I'll go with the second option for now but I think it's more bombproof if it can be added as a future module (I'll make a feature request :))

EDIT: Diogo, could you move this to feature requests?

Link to comment
Share on other sites

 Done, moved it Wishlist & Roadmap

--

Just a detail, but maybe I would change the order in my second solution:

$link = $page->urlfield || $page->pagefield->url;
  • Like 1
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

×
×
  • Create New...