Forum

Thread tagged as: Question, Configuration, Api

Is Perch right for me?

Hi -

I want to add a CMS to our website: https://www.addtothenoise.com/portfolio/portfolio.html#all

the portfolia is practically a SPA with the data added from a JSON object like so: https://www.addtothenoise.com/portfolio/js/portfolio_content.js

My wife is the designer and she wants to update - hence the need for a CMS. As in the subject line: can I use Perch in such a manner, or is there a suggested way to achieve this?

Thank you,

Uli

Ulrich Sinn

Ulrich Sinn 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Hi Ulrich

Yes, you can manage anything text-based, so HTML or JSON or whatever.

That site looks like it would be pretty simple to put together with Perch. For your JSON, you'd create a template something like this:

{
      "index": "<perch:content id="perch_item_index" type="hidden" />",
      "id": "<perch:content id="id" type="text" label="Item ID" required="true" help="Lowercase, no spaces. Start with a letter" />",
      "category": "<perch:categories id="category" set="portfolio" label="Category"><perch:category id="catSlug" /></perch:categories>",
      "thumbnail_src": "<perch:content id="thumb" type="image" width="130" height="127" crop="true" label="Thumbnail image" />",
      "image_src": "<perch:content id="largeimg" type="image" width="393" height="364" crop="true" label="Large image" />",
      "color": "<perch:content id="color" type="color" label="Color" />",
      "width": "<perch:content id="width" type="number" label="Width" min="1" max="1000" />px",
      "height": "<perch:content id="height" type="number" label="Height" min="1" max="1000" />px",
      "title": "<perch:content id="title" type="text" label="Title" required="true" escape="true" />",
      "client": "<perch:content id="client" type="textarea" label="Client" escape="true" size="s" />",
      "detailImages_src": [
                  <perch:repeater id="detailimgs" label="Detail images">
                        '<perch:content id="detailimg" type="image" width="980" label="Image" />'<perch:if not-exists="perch_item_last">,</perch:if>
                  </perch:repeater>
                        ]
  }

In short... YES. Perch can output (and does) the json you need. It's pretty straight forward, but does require a tiny bit of PHP knowledge to setup. Can you give a sample piece of code you would be expecting from perch?

Thank you! I might start fooling around with this until I hit a road block.

This works great!

<?php include('perch/runtime.php'); ?>

<?php

echo(json_encode(perch_content_custom("PortfolioItem",
        array(
            'page' => '/portfolio.php',
            'template' => 'addtothenoise_portfolio_item.html',
            'skip-template' => true
        )
    )
))
?>

Highly likely that this is a rather brute force approach, but I only spent some time with Perch since Monday. Thank you!