Giter Club home page Giter Club logo

blockscontent's Introduction

Blocks Content alpha

(c) 2013 by Soma

Module to help create content blocks for pages. The blocks are defined by normal templates you create in ProcessWire and their template file is used to render the output.

This is a first alpha version for testing and getting it out to people for looking at it and getting feedback.

Requirements

  • To develop this module I used dev version of PW. Not sure there's anything dependent and I haven't tested in 2.3 stable, but should be fine.

  • The module currently uses Fredi to build the edit modal on front-end. http://modules.processwire.com/modules/fredi/

Setup

  1. Install Module Blocks Content: will also install Process Blocks Content
  2. The module also creates a new template pwbc_blocks_parent, that is used to create the remote parent page in the admin for storing the blocks as children. Use the family children setting to limit creating blocks using your block templates you going to create.
  3. The module also creates a new page field pwbc_blocks_select. This is used to manage and create the blocks in the admin. Add this field to templates you want to create blocks for. It has a special custom php code. Leave as is, but you can change the label for example.
  4. Create some block templates. Do this with a prefix block_. It will automaticly recognize them and set the template file (php) to be in /site/templates/blocks/.. Create the template file in there using the same name. i.e. if you create a block_image-text you create the partial template file /site/templates/blocks/block_image-text.php. Also set the family setting to not allow children, as this will also hide the children tab on editing views.
  5. As mentioned earlier: Use the family children setting of the pwbc_blocks_parent template to limit creating blocks using your block templates.

Template code

For now you can use this code to output the blocks in the template file:

Somewhere at the beginning of you templates (head.inc or _init.php) you would load the BlocksContent and Fredi module and output the scripts like:

$blocks = $modules->get("BlocksContent");   
if($user->isLoggedin()) {
    $fredi = $modules->get("Fredi");
}

Now in the head of your html output you render the scripts required:

if($user->isLoggedin()) {
    echo $fredi->renderScript();
    echo $blocks->renderScript();
}

Then use this code in your template where you want the blocks of the page to output:

echo $blocks->render();

That's it for now.

Here is an example block template code I used:

<div class="block cf">
    <h2><?php echo $page->title?></h2>
    <?php if($page->image): ?>
    <img class="<?php echo $page->image_align;?>" src="<?php echo $page->image->size(250,0)->url?>"/>
    <?php endif; ?>
    <p><?php echo $page->body; ?></p>
</div>

Now when you create or edit a page, you'll have an empty "Create Blocks" field with a "+ Add new block" link. Create new blocks and publish them, after closing the modal, the newly created block will appear in the ASM select. Save the page and view it on the front-end. Have fun.

Create as many block templates, text-image, repeater for link-lists, videos with text etc.

When clicking on the label of a block entry in the ASM select, you can open the modal for editing.

Sorting the blocks in front-end will sort them in the ASM select and the other way around.

When removing a block from the ASM select and saving the page the block will get deleted. Deleting is currently not possible from the front-end.

Also there seems to be an issue with deleting blocks in the backend when using the modal "Move to trash" button you see at the bottom. This is because ASM select widget isn't really yet used like this, apart from the field editing on templates.

blockscontent's People

Contributors

somatonic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

lisandi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.