Jump to content

Re-use the field multiple times in Single Page Template


JeevanisM
 Share

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

 

Link to comment
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
Link to comment
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
Link to comment
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 ? 

Link to comment
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
Link to comment
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

Link to comment
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
Link to comment
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
Link to comment
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

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