Jump to content

12 identical templates but with a small piece of different code: can I use processwire to create a single template?


Recommended Posts

Hi everyone.
I've created 12 templates that are the same but each with an extra bit of html code. 
The piece of code is as follows:

						<div>
							<div class="box-pf">
								<i class="fa fa-map-pin fa-2x fa-red faa-pulse animated"></i>
								<a href="">
									<span class="uk-text-middle"><i>Sonchus oleraceus</i> 'Grespino degli Orti'</span></b>
								</a>
							</div>	
						</div>	

On the third line we read "fa-red."
I created 12 similar templates.
The first template has only one box with fa-red, the last template has 12 boxes with icons of 12 different colors.
So. is there any way to have only 1 template and add, if I want and when I want, a small or big, same or different piece of html code?

 

Link to comment
Share on other sites

There are a tons of ways to do what you're asking, so I'm just suggesting something based on your previous example.
In the template add a repeater field "repeater" and add to it 3 fields (name whatever you want, just stick to mine if you want copy/paste the code block below):

1) class_string
2) title
3) description

All of them are of type "text".

Fill them as you like.

In the template file then paste this code where you need them to be placed.

<?php foreach($page->repeater as $block): ?>
<div>
	<div class="box-pf">
		<i class="<?= $block->class_string ?>"></i>
		<a href=""><span class="uk-text-middle"><i><?= $block->title ?></i> '<?= $block->description ?>'</span></b></a>
	</div>	
</div>	
<?php endforeach; ?>

 

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

  • 7 months later...
On 1/26/2021 at 1:33 PM, 3fingers said:

There are a tons of ways to do what you're asking, so I'm just suggesting something based on your previous example.
In the template add a repeater field "repeater" and add to it 3 fields (name whatever you want, just stick to mine if you want copy/paste the code block below):

1) class_string
2) title
3) description

All of them are of type "text".

Fill them as you like.

In the template file then paste this code where you need them to be placed.

<?php foreach($page->repeater as $block): ?>
<div>
	<div class="box-pf">
		<i class="<?= $block->class_string ?>"></i>
		<a href=""><span class="uk-text-middle"><i><?= $block->title ?></i> '<?= $block->description ?>'</span></b></a>
	</div>	
</div>	
<?php endforeach; ?>

 

Hi fingers, since you said there are MANY ways to do what I was asking, could you suggest another way?
The one you suggested is fine, but if possible I would like to avoid the repeater module. Maybe there is a solution in pure php language or with pure processwire api?

Link to comment
Share on other sites

many ways...

1. use childpages instead of repeaters would be possible
2. repeater matrix (pro module)
3. pagetable module
4. editing the https://processwire.com/modules/fieldtype-events/     to your needs this is a example for repetable items in a small amount in a own fieldtype module
....this comes in the first minute of thinking about your question.
processwire API code goes the same as for repeaters with different sources of the content (get childpages instead of repeateritems and so on)...

kind regards mr-fan

  • Like 2
Link to comment
Share on other sites

35 minutes ago, franciccio-ITALIANO said:

well i wanted to avoid ANY special module, to find a solution with only generic php language, anyway i will use the repeater, still i didn't learn how to use page categories and child pages... 

Hi,

depending on why and/or where those pieces of code are displayed or not, it could be easy to do this with php
for example, if one of these piece of code is displayed when/if the page is a child of some page or template, easy to have a php if based on the parent template or id

another way to do this, safe if it is your website, meaning some education if it is a client's one... would be to use toggles for the template "display this... yes/no", once more a simple check on the toggle value with php, job done (i've used this solution for a client who wanted some pages to be published, not hidden => in the sitemap but not always in the menu

pw and php are great friends 😄

have a nice day

  • Like 1
Link to comment
Share on other sites

On 9/12/2021 at 8:57 AM, franciccio-ITALIANO said:

well i wanted to avoid ANY special module, to find a solution with only generic php language, anyway i will use the repeater, still i didn't learn how to use page categories and child pages... 

knowing page categories and child pages - or the usage of templates and pages as contentcontainers for everthing you ned - is essestiel!!

this is a great startpoint for learn this very very important thing - processwire manage the content you need - with simple PHP solutions you get get the content in your templates...i created a complete blog logic without a special module or something else - but you have to know to use pages and fields and learn this things.

 

  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By theExo
      Hey folks,
      im pretty new to Processwire. A client of mine asked me to migrate his old (v2.5) Processwire Website. On his server its running on PHP 5.3 and i want to upgrade + migrate the site at the same time. I Downloaded the Site from his server to set it up locally, replaced the /wire directory, index.php and .htaccess with the files of the latest version. After that i changed the DB Connection details in the config.php, swapped to PHP 7.4 and now, when i open up the site on my localhost i get this error:
      compile(\ProcessWire\wire("config")->paths->root . "site/templates/includes/head.inc.php",array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)))?> compile(\ProcessWire\wire("config")->paths->root . "site/templates/includes/header.inc.php",array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)))?> compile(\ProcessWire\wire("config")->paths->root . "site/templates/includes/start_content.inc.php",array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)))?> compile(\ProcessWire\wire("config")->paths->root . "site/templates/includes/footer.inc.php",array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)))?> The page itself doesnt load, just a white space with this stuff on it
      I checked if the files exist, they do.
      I hope anyone can help me with that 🙂 Thanks in advance!
    • By Neue Rituale
      https://github.com/neuerituale/FieldtypeOembed
      or in the modules directory: https://processwire.com/modules/fieldtype-oembed/
    • By OrinTerry
      Hello everyone. I am running a small technology blog, which is in WordPress. The main problem with my blog is that it does not open on any Windows 7 computer normally. I know Windows 7 has lost official support from Microsoft but still, there are plenty of users who still use Windows 7. The blog site is already 'HTTPS' protected but after opening in any browser, it shows 'not protected' next to the URL box. So, if I migrate all the site data to 'ProcessWare', will I get the same problem here too? Any kind of feedback would be greatly appreciated.
    • By Marvin
      Hello, excuse me
      I'm new at processwire, i want to ask about a master detail system (Inheritance system) using a processwire. Can we create a Inheritance table using a processwire, and how we create it? Thank you for the help
    • By pideluxe
      From the recent discussion about the roadmap & wishlist for 2021 and some other posts by @ryan, it comes to my mind that developing and coordinating the whole project for one person is becoming harder and harder and leads nearly to the reverse of expanding the ProcessWire ecoysystem. This is not against Ryan, i think everyone here knows how engaged he is about ProcessWire, but he has only 24/7 (sometimes i think he's got far more than that...). 
      We as the community could support the project (financially) to relieve Ryan and could take over some tasks from him. This could be, but is not limited, to:
      Building a Foundation/Association/Company to ensure the persistence of the project and to fund the work put in ProcessWire of Ryan (and others). Nearly every other CMSs i checked has something like this (Drupal Association, Typo3 Association, Joomla Foundation, Wordpress Foundation, Contao Association, ...). This also puts more trust in the project, if someone new will check on his engagement in ProcessWire. Assigning persons/teams to work on things: Extending the core (when necessary) Developing and maintaining major modules (e.g. page builder, admin themes, internationalization, marketing, ecommerce system, ...) Testing and inspection of modules developed by others Making translations of modules (translation of the core is mostly covered, i think) Working on PRs & issues submitted on github Working on the homepage Coordinating the community efforts I know, some resorts are already covered by others (e.g. @Pete for the forum, @horst for images, ... ), but there are many other areas where this ist not the case. By joined efforts by the ProcessWire community this hopefully will also attract new developers to the system and by a growing number of users this assists in the things above in a circular process. What do you think? 
×
×
  • Create New...