Posts by hus_hmd

    Hi!


    A few months ago I started using Tinkerwell, which is a code editor to tinker with PHP code. It ships with built-in support for some PHP frameworks and CMSs, but you can write a driver for any PHP application (e.g. Perch).


    In the context of Perch, I find it useful when building Perch add-ons as well as general Perch development. For instance, you can quickly inspect how the data is returned when you skip the templating (e.g. when using perch_collection() or perch_categories()). Or you can play with Perch API and Runway's headless mode.


    EZL227OWkAIBwXa?format=jpg&name=large




    I have opened a PR on GitHub to add a Perch driver, but it has not been accepted yet.


    In the meantime, you can manually add the driver to your Perch projects:

    1. Download it from here
    2. Create a .tinkerwell folder at the root of your Perch project
    3. Place the PerchTinkerwellDriver.php file inside the .tinkerwell folder

    I looked into Snipcart to provide an option for a client a while ago. The default way is to include their JS on your page and define the products via the HTML as detailed on their docs (https://docs.snipcart.com/v3/setup/products):


    HTML
    1. <button class="snipcart-add-item"
    2. data-item-id="starry-night"
    3. data-item-price="79.99"
    4. data-item-url="/paintings/starry-night"
    5. data-item-description="High-quality replica of The Starry Night by the Dutch post-impressionist painter Vincent van Gogh."
    6. data-item-image="/assets/images/starry-night.jpg"
    7. data-item-name="The Starry Night">
    8. Add to cart
    9. </button>


    So you can create a Runway Collection (or a multiple-item region if you're using standard Perch and don't have too many products):


    HTML
    1. <button class="snipcart-add-item"
    2. data-item-id="<perch:content id="_id">"
    3. data-item-price="<perch:content id="price">"
    4. data-item-url="/products/<perch:content id="slug">"
    5. data-item-description="<perch:content id="desc">"
    6. data-item-image="<perch:content id="image">"
    7. data-item-name="<perch:content id="name">"
    8. >
    9. Add to cart
    10. </button>



    You can also use their API to define products from JSON (https://docs.snipcart.com/v3/a…ce/products#post-products). So you can write a small Perch app that listens to Collection items events (created/updated/deleted) and interact with the Snipcart API accordingly.



    As for inventory, once a product has been defined and created in Snipcart, you can manage the inventory through the Snipcart's dashboard (https://snipcart.com/ecommerce-inventory-management). This means the editor would need to create the product via the Perch control panel, then head over to Snipcart to manage the inventory.

    If I have a Collection of member biographies (with different field types like text and image), does this mean that a member or admin user would be able to edit these?


    Yes! Someone who's registered as a member via the Perch Member app would be able to edit this.




    A member should be able to edit their own biography not others. Is that possible?

    Assuming the collection items are linked to the relevant members (e.g. by relating them using the Members field type), you can only display the edit form to the relevant member.


    In a member-only page, you can filter by the member ID:



    And you can expand this to a list/detail pattern where the member is allowed to create/edit multiple items (e.g. a ticketing system):



    So you are controlling what items a member edits.


    The one thing this lacks right now is stricter checks at the form handler level. While the form is CSRF protected, a malicious user technically can edit the values of the hidden _id and member fields on the form.


    Normally you'd check the logged in member submitting the form is the same member linked to the item. The reason I have not implemented this check in Pipit Members yet is I find the identifying link to the collection item is not necessarily the member ID. So I'm working on implementing a way to allow you (the developer) to define this check.

    I've recently released Pipit Members v1.1.0 which makes it easier to allow members (registered with the first-party Perch Members app) create/edit/delete collection items via Perch-templated forms:




    This essentially makes it easier to build CRUD apps with Perch Runway without having to write your own custom Perch apps. You would use:


    I'm posting here to open a dialog with other developers. So feel free to share your thoughts, request features that would make it even easier for you or ask questions.

    Assuming you are using a Perch-templated form like the example in the docs:


    You can generation the options in PHP:

    HTML
    1. <perch:input type="select" id="location" options=",<perch:forms id="cat_opts">">



    Or you can generate the options in a separate template:

    categories/select_opts.html:

    HTML
    1. <perch:category id="catTitle">|<perch:category id="catSlug"><perch:if not-exists="perch_item_last">,</perch:if>

    I don't recall coming across this myself. A quick Google search suggests you may see this if your server does not support gzip compression. So I would:


    • Enable gzip compression on the server
    • If that doesn't work, check your error log and/or turn on Perch debug mode

    Hi Tony,


    The slug you generate does not need to include the item's unique ID in order for you to use it in the item's URL and when fetching the item from the database. The item's URL in your template can be something like this:


    HTML
    1. <a href="/post.php?s=<perch:content id="slug">-<perch:content id="_id">">
    2. <perch:content id=title">
    3. </a>



    In your PHP page, you can get the value of ?s= (i.e. the item's slug in this case) with perch_get('s') and separate the last segment of the slug:



    I'd personally use the _id option (because Perch uses a faster a database query with it), and check the slug from the URL matches the slug I get from the database in PHP:


    PHP
    1. $item = perch_collection('Blog', [
    2. '_id' => $ID,
    3. 'skip-template' => true,
    4. 'return-html' => true,
    5. ]);

    Hi Tony,


    Yes, this is possible. One approach is to use layout includes inside the template and pass layout variables:


    HTML
    1. <perch:layout
    2. path="products"
    3. categories="<perch:categories id="category" set="products" label="Category"><perch:category id="catPath" append=","></perch:categories>"
    4. >


    Given that layouts are rendered at a later phase than normal content, when Perch renders them it will see the tag as something like:


    HTML
    1. <perch:layout
    2. path="products"
    3. categories="products/shoes/,products/shirts/,"
    4. >


    So the above is the equivalent to:


    PHP
    1. perch_layout('products', [
    2. 'categories' => 'products/shoes/,products/shirts/,'
    3. ]);



    Inside your templates/layouts/product.php, you can access the categories with perch_layout_var():