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

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.

  • Similar Content

    • By Guy Verville
      I am trying to implement a Repeater Matrix which contains a Page field (there are four fields, an image field, one text field and two page fields). The example given in the readme.txt is self-explanatory. However, this seems not to work with a page field. Say my page field is called "attached_ceramic_skus":
      <?php foreach($page->test_matrix as $item) { echo " <h3>$item->headline</h3> <=works <img... $item->image->url </> <= works foreach ($item->attached_ceramic_skus as $skus)... <= throws an error "; } } } When I debug this line, I see my image and text fields in the $item array, but not the page fields. But these fields are there and working when I enter data. I have understood how they are kept in the database. What is the method/hook to read this type of field?
    • By danielsl
      latest development version tryed adding url_link field (URL) unfortunately experience this error
       
      Session: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'expo_ch.field_url_link' doesn't exist trued recover db and add field again, every time same result
      any ideas how to create url link and add it to a repeater
      ui Session: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'expo_ch.field_url_link' doesn't exist
      SQLSTATE[42S02]: Base table or view not found
      SQLSTATE[42S02]: Base table or view not found
    • By mikeuk
      (apologies if this looks too similar to previous topic I created, seems more logical as a new topic)
      I'm curious if anyone here is implementing something along the lines of Drupal's block / Joomla's custom (editable) module functionality?
      In other words, areas that are editable in the backend, that can be placed on multiple pages without needing to re-enter the content on each page it is used.
      I tried to do this using a page as a block, and then field type Page (to get a page within a page), but this led to issues with rendering, and more important this creates an object $page->fieldtypePage which is exceptionally large, so I would prefer to avoid that route.
      My guess is those that do it, do it outside of PW with PHP. But the 'blocks' being editable and creatable by a site editor is important so I need to explore this or find a different solution (or tell the client no-can-do).
    • By Matt
      Hello everyone! I recently downloaded ProcessWire and after playing around with it I've found its flexibility and ease of use to be really promising.
      I'm working on a site to publicize upcoming live music events and archive past events at our venue. Each event has the usual start time/end time/price/etc fields and can be associated with any number of bands (usually just one or two). Each band has name/website/description (short bio)/image fields. At the moment I have a page field on my event template allowing each event to be tagged with the required bands, either by choosing existing band pages (for bands which have played at our venue before) or by creating a new band page. I can then reference each band's name/website/description/image in the event template php.
      There are two key ways users will discover events on the public-facing site:
      1) Through the events index page, listing events which can be filtered using dates and keywords
      2) Through the band index page, listing bands whose pages will list past/upcoming events where they have performed.
      However, since:
      a) many bands have gone through minor lineup changes since they started playing at our venue,
      b) many bands have released (and want to promote) new material since they started playing at our venue,
      each band's description and image fields might (but not always) need to vary between events. I would like past event pages to show the band's description/image that was relevant when the event occurred, not the most recent revision. On adding band pages to new events pages, I would like the default description/image to be the most recent version for the band, with the option to replace this with a new description/image if required. It would be unnecessary to provide a new description/image for each band at each event if there were no lineup changes or releases of new material since they last performed.
      My first thought was to have a repeater field for description/image/start time/end time on the band template, where the start and end times help my php template decide which description and image to pair with a particular event. However, the band page field on the events template will not allow me to edit the referenced band page's attributes; it only lets me select band pages and reorder them. If I wanted to update the band description (while preserving the history of previous revisions) I would therefore have to find that band's page elsewhere in the admin then add a repeater row and enter the new description there, keeping the image field blank for that row if the image doesn't need updating. This would require the start time (of the new row) and end time (of the previous row) to be input manually... I'm convinced there must be a simpler way to maintain the links between events and band info.
      My current structure is:
      Home
      -- Events Index
      ---- Event 1
      ---- Event 2
      ---- Event 3
      -- Bands Index
      ---- Band 1
      ---- Band 2
      ---- Band 3
      Apologies if I've misused any terminology  Could anyone advise on sensible strategies for achieving this using Core ProcessWire or modules? Thanks!
    • By abdus
      Hey,
      I'm building a website with following page hierarchy
      home/     /blog (template: listing)         /tags (template: tags)             tag1 (template: tag)             tag2             tag3         post1 (template: post)         post2         post3     /development (template: listing)         /tags (template: tags)             tag1 (template: tag)             tag2         post1 (template: post)         post2
      Ok, so I created a Page field to reference tag pages for categorization of posts in different listings. I set up the field to use InputfieldPageAutocomplete module for quickly referencing and creating any number of tags within a post. However, during the setup, Processwire allows me to pick only one parent. I want to change this behaviour such that when searching for a tag, it should only search under its own listing. Specifically, posts under /development should only be able to reference tags under /development/tags and those under /blog should reference tags under /blog/tags etc. Also, when I create a new tag, it should create under its own tags page.
      I don't want to use a tags page under the homepage, because I want the URL structure to be /blog/tags/journal or /dev/tags/processwire etc, not /tags/processwire. I know I can use input()->urlSegments to achieve the url structure I want, and I did it like that in the past, but it felt too hacky to change the paths for pages from their own path in page tree. I tried hooking into InputfieldPage:processInputAddPages method to make the field accept the correct tags page, but I couldnt make it work.
      How can I achieve this?
×
×
  • Create New...