Jump to content
JeevanisM

Re-use the field multiple times in Single Page Template

Recommended Posts

Hi All,

I am trying to build a PW website upon the  HTML design as shown here : https://bit.ly/2HxZbwr

As you can see,  I use a repeated block to display a divider between sections on the page, its an image background-text on top. The screenshot is here : 04c4051c-1254-4a7a-a331-33e185456ee2.png

Now, I created a new field for this block content and attach that field to my Home Page template. But in HTML design, I used this block in two places, on on top side, and one on the footer. Now, when I do it in PW, can I use one same field multiple times in a single page template ? I have read this thread about using fields in efficient way, but I could not figure out, how to use same field multiple times in a page template.

I hope I did not confused any one with my query, please let me know the correct PW way to achieve  this.

 

thanks

Jeevz

 

Share this post


Link to post
Share on other sites

Fields can only be used once per page, this is mainly by design.

But your template may have multiple fields from the same fieldtype (like image1 and image2).

If you need multiple instance of the same field(s), you may use a repeater (or Table, Multiplier or RepeaterMatrix from the ProFields).

  • Like 5

Share this post


Link to post
Share on other sites
33 minutes ago, JeevanisM said:

can I use one same field multiple times in a single page template ?

No, you can't use the same field multiple times on a template...

There are repeatable fields, like Profields Multiplier, Repeater, PageTable, or even Profields Textareas, etc, for when you need to have multiple iterations of a field on the same template...

  • Like 1

Share this post


Link to post
Share on other sites
Just now, Macrura said:

No, you can't use the same field multiple times on a template...

There are repeatable fields, like Profields Multiplier, Repeater, PageTable, or even Profields Textareas, etc, for when you need to have multiple iterations of a field on the same template...

thanks for quick reply, yes I was reading about Repeaters but I could not figure how to use it in two different place in a same  Page Template. I understand that I can use Repeater to convert  3 static HTML  col-6 Blocks, but this is in a consecutive manner. For example ( 3 block divs, showing one image with small descr in Homepage ). But my situation is different. I need to show a content block in different places in a Page, its not in a consecutive way. Say, I have a field <Simple Quote Display > , I want to display Different Quote in different places in my home page. Right now I am creating field Quote 1, Quote 2 etc. I wanna know is there any another method to achieve this ? 

Share this post


Link to post
Share on other sites

Repeater Matrix sounds like a good fit for this. Believe me, the Pro Fields module is worth every cent.

  • Like 2

Share this post


Link to post
Share on other sites
Just now, dragan said:

Repeater Matrix sounds like a good fit for this. Believe me, the Pro Fields module is worth every cent.

thanks, I will check it out

Share this post


Link to post
Share on other sites
10 minutes ago, dragan said:

Repeater Matrix sounds like a good fit for this.

Just wrote the same... 😉

Sadly the ProFields description currently miss screenshots, so its probably little difficult to get an idea about how RepeaterMatrix works.

https://processwire.com/store/pro-fields/repeater-matrix/

With the RepeaterMatrix you basically define a sequence of elements producing content for your page. Each element has one or more field(s) containing stuff like images, text or whatsoever. Items may also have a "depth", which could map to div containers, for example. Here are two screenshots how this may look in the backend:

:PwNestedRepeaterMatrix.thumb.jpg.e46b4d55c0c1199debf51ad1eb1488e3.jpg

RmPreview.thumb.jpg.1998bfd3e722fe47d892af88498b1176.jpg

The second one generates this page: https://www.team-tofahrn.de/en/projects/organ-story/

  • Like 7

Share this post


Link to post
Share on other sites

I will explain my issue again : As you can see my HTML Design, there is a page division block  between different sections in layout.  Example - in the design here you can see a background image with text on top div bar just above Our Message. The same block is used just in the footer ( above footer log, supporr , learn more menu ) . So, in Processwire, we create fields to manage dynamic content right? Now, this division block, I want to do different text content in different places. For example, in footer, the text content would be , " hello this is footer " , an on top side, the div will have "Hi, this is not a footer". I know I can create a field for this in PW Admin, display the content, but I can only add this Field only one time in a Template right ? I mean, I am adding this in my Home Template. What to do, if I need to use same  field twice or multiple times in same Page template. Right now, I can create two fields to solve my issue , one field for top side, one field for footer side, but I just wanted to make sure that I was not doing a dumb method, if a better approach is available in PW.  Note that I  know  I can use Repeaters, but it should be in a consecutive blocks, I already implemented that in the section "Our Message" .


this is was query, hope no more confusion

Share this post


Link to post
Share on other sites
3 hours ago, JeevanisM said:

What to do, if I need to use same  field twice or multiple times in same Page template.

You cannot use the same field multiple times in one page. What you'd need to do is use a field, which allows you to add multiple "sub-pages" like repeater / page table / pro field matrix. You could also simply use the pages children if you want. There are a few other multi value fields in processwire, but those don't seem to fit what you're describing.

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, JeevanisM said:

Note that I  know  I can use Repeaters, but it should be in a consecutive blocks

is there a 'not' missing? You still may use a repeater for your purpose, there is no need to output repeater's content in consecutive blocks. Never tried it, but a repeater effectively is a WireArray and should provide the method getIterator(). So in your output code you may fetch the first element whereever you like to place it, fetch the second later etc.

If the content of the separators repeat over pages, you may also use a completely different approach and manage those separators as individual pages (with an own template) in some hidden section of your pagetree. On your "content" template you simply place a field of FieldtypePage (named Page Reference) and point to the separator to use. You still need two such fields, one for the header and one for the footer. Downside is, that the separators are managed separately.

There are so many options, but I'd still prefer RepeaterMatrix for such purposes. And when I say "for such purposes" I don't mean to only define the separators with a RepeaterMatrix but the complete page layout (including text content, images, rows of blocks etc.. That way you are able to control layout, section order etc. from the GUI and do not need to modify PHP code for each change.

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, Autofahrn said:

is there a 'not' missing? You still may use a repeater for your purpose, there is no need to output repeater's content in consecutive blocks. Never tried it, but a repeater effectively is a WireArray and should provide the method getIterator(). So in your output code you may fetch the first element whereever you like to place it, fetch the second later etc.

If the content of the separators repeat over pages, you may also use a completely different approach and manage those separators as individual pages (with an own template) in some hidden section of your pagetree. On your "content" template you simply place a field of FieldtypePage (named Page Reference) and point to the separator to use. You still need two such fields, one for the header and one for the footer. Downside is, that the separators are managed separately.

There are so many options, but I'd still prefer RepeaterMatrix for such purposes. And when I say "for such purposes" I don't mean to only define the separators with a RepeaterMatrix but the complete page layout (including text content, images, rows of blocks etc.. That way you are able to control layout, section order etc. from the GUI and do not need to modify PHP code for each change.

Sounds like a workable hack... Will try and update

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Mithlesh
      Changing it to null
    • By Mithlesh
      Hi, I have one URL - writerrelocations.com/contact-now/

      I have one issue where my header Image is appearing again after the contact form, for your reference:



      I have checked my processwire template section where have not added any Image field besides Header Image, attaching the same for the reference:




      PLEASE help me to get rid of the image below contact form

      Waiting for the swift response!

      Thanks
       
    • By Liam88
      Hi all,
      Quick question as I haven't found anything from my Googling. 
      I have a blog on the site which utilises pagination. On the standard blog page I have a custom header which has featured posts.
      Below that I then have recent posts like mosts blogs.
      Now if i click to page two or three I want the header to disappear and just show a continuation of the standard posts.
      I'm not sure how to go about this so any direction would be helpful.
      Thanks
    • By NorbertH
      As we are building some webapplications with the PW backend , having those really big spacings between all field elements in forms and everywhere is not too practical. 
      UI Kit already has less spacings between all elements than Bootstrap for example , but i am looking fore a more condensed BE Theme.  Maybe someone already made something like that?
    • By VeiJari
      Hello, our customer doesn't like the fact that they have to first add a title and then add the other info in the form. Therefore, we've enabled the way to skip this by making a temporary file before saving.
      But the problem is that by using module schedulepages in this piece of code in the module:  
      if (!$page->isNew() && $page->publishable() && $page->isChanged('status') && $page->is(Page::statusUnpublished) && $page->publish_from) {
                  $this->session->error($this->_("“Publish From Date” field was cleared to prevent the page from being unintentionally re-published on the next Lazy Cron run."));
                  $page->publish_from = null;
                  $page->save('publish_from');
              }
      it fires even with the temporary file and therefore after first save it resets the publish_from field. Is there a way to check if template is temporary, or something along those lines?
      One solution is just to ask the customer to first save the form after adding a title, but I don't see that as a good solution.
×
×
  • Create New...