Forum

Thread tagged as: Question, Discussion

Updating/Modifying Templates

Let me first say how much fun I've been having learning Perch/Runway. I'm planning on using it for a couple upcoming projects that normally would have gone the Wordpress route. Perch looks to be a wonderful alternative. Great job Rachel & Drew!

My question is about modifying templates. When I am experimenting with different options/markup/css in an existing template, the content using the template doesn't update unless I re-save it in Perch. I learned about the Republish button in another thread which is great. Although, it feels a little heavy-handed to republish ALL the page if I'm just experimenting with a single template. I saw in the documentation that perch_content_custom() doesn't cache.

So my question is if there's a big issue with creating my regions like this:

perch_content_create('My Region');
perch_content_custom('My Region');

...instead of using perch_content(). Using the above method, I found I could edit my template and just refresh the browser to see the results. It feels like a better workflow for me. The docs say you can take a performance hit, but as long as I'm not dealing with 1000's of items, I'm wondering of that's an OK technique for creating regions.

Thanks!

Dustin Tauer

Dustin Tauer 0 points

  • 1 month ago

Hello Dustin,

You can serve the cached content in your production/staging environment and output the uncached content in your development environment if you set the production mode in your config files: https://grabapipit.com/blog/utilise-perch-production-modes

$my_region = perch_content('My Region', true);

if (PERCH_PRODUCTION_MODE === PERCH_DEVELOPMENT) {
  // development environment - output uncached
  perch_content_custom('My Region');
} else {
  // production or staging environment - output cached
  echo $my_region;
}

Thanks Hussein! I never thought about using environment variables to make it easier. I like that it allows me to still take advantage of the caching.