Code Monkey home page Code Monkey logo

html_panel's Introduction

HTML Panel Field

Purpose

To allow the creation of rich views of data in the Symphony backend, using only Symphony's native tools (Pages, XSLT and Data Sources). To reduce the barrier to entry of embedding of content within the Symphony backend without so that developers do not experience of creating Extensions and system Fields. "So easy a frontend developer could do it!"

Installation

  1. Upload the 'html_panel' folder in this archive to your Symphony 'extensions' folder
  2. Enable it by selecting the "Field: HTML Panel", choose Enable from the with-selected menu, then click Apply
  3. The field will be available in the list when creating a Section

Configuration

When adding this field to a section you must provide a URL Expression. This is the URL of the HTML to display in the backend. This can be relative such as /my-page or absolute e.g. http://mydomain.com/my-page. Values from other fields in the entry can be used to build the URL and are included using XSLT syntax:

/order-summary-panel/{entry/@id}

The available XML to choose from is a full <entry> nodeset, as you would normally see through a Data Source. All fields are included in this XML.

Example of use

This is a quick example to show how an HTML Panel field can be used to display an order summary from a one-to-many section relationship between Orders and Order Items.

The Orders section comprises a Name (reference) and Date field:
Orders section

Entries in the Order Items section store the item name, unit price, quantity and which Order they are assigned to:
Order Items section

Viewing the Orders section a user sees the normal fields plus an HTML Panel field showing the order summary:
Order entry

The HTML Panel field is configured to point to a local Symphony page, passing the viewed (Order) entry ID in the URL:
Order Summary page snippet

The order summary table is actually served from a frontend page with a Data Source attached, filtering Order Entries by the URL Parameter {$order}: Order Summary page snippet

The XSLT for this page simply creates an HTML table and nothing else:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

<xsl:template match="/">

	<table>
		<thead>
			<tr>
				<th>Item</th>
				<th>Quantity</th>
				<th>Unit Price</th>
				<th>Total</th>
			</tr>
		</thead>
			<tbody>
			<xsl:for-each select="/data/order-items/entry">
				<tr>
					<td><xsl:value-of select="item-name"/></td>
					<td><xsl:value-of select="quantity"/></td>
					<td>£<xsl:value-of select="unit-price"/></td>
					<td>£<xsl:value-of select="number(quantity * unit-price)"/></td>
				</tr>
			</xsl:for-each>
		</tbody>
	</table>

</xsl:template>

</xsl:stylesheet>

Styling HTML Panels

The extension provides a single html-panel.css which controls global styling of content within HTML Panel fields. Any custom styling should not be put in this file. Instead, each HTML Panel instance is given its own unique ID. For example an HTML Panel field named "Order Summary" in a section named "Orders" will render an HTML container:

<div class="field field-html_panel">
	<label>Order Summary</label>
	<div id="orders_order-summary" class="html-panel">
		...
	</div>
</div>

You can create styles and behaviour by creating files at the following locations:

/workspace/html-panel/orders_order-summary.css
/workspace/html-panel/orders_order-summary.js

If these files exist, they will be automatically added to the <head> when the page loads. Your CSS can then target its specific HTML Panel:

#orders_order-summary {
	...
}

Fields that store values

The above example is read-only — it just displays something. As of v1.2 HTML Panel can be used to build fields that store values too! You don't need to do anything too fancy. Start by passing the field's value in the URL to the page that builds the panel:

/my-page/?value={entry/my-field-name/text()}

In your XSLT you can then grab this value and build an input element. So long as you give the input element a name that matches your field name, its value will be saved to the entry. For example:

<input type="text" name="fields[my-field-name]" value="{$url-value}" />

A word on security

As michael-e points out the above example is rather insecure if you are actually displaying order information on a public URL. You should test in XSLT for the existence of a $cookie-username parameter (your Symphony author username), or use the Login Info event attached to your page to get more information about the user. An even better option is to pass a known parameter on the querystring such as ?password=mypass and test for this in XSLT.

Other uses

Use your imagination:

  • allowing the user to enter a YouTube video URL in a text input field, and embedding it directly with an HTML Panel in the backend as a preview
  • when multiple Images are assigned to an Article, an HTML Panel could display a read-only list of thumbnails with "Edit" links directly to these entries in the Images section (a type of read-only Subsection Manager field)
  • when viewing a user profile, pull in a list of their most recent orders, posts or comments for review. Perhaps if you're building a moderation system, you pull in all un-moderated comments for a post
  • embedding Google Charts or Google Maps
  • making web service calls to third party application such as Google Analytics, stock/inventory/fulfilment systems etc

html_panel's People

Contributors

ahwayakchih avatar animaux avatar brendo avatar johnpuddephatt avatar michael-e avatar nickdunn avatar nitriques avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

html_panel's Issues

Issue with empty URL expression

When no URL expression is inserted at field creation in section, the sections' entries are messed up. Image attached in Symphony forum.

There's no TIMEOUT captain?

Was debugging a slow section our preview site today and found that the CURL request for the expression has no timeout value.

Adding a timeout resolved the slowness (well to a degree).

Perhaps this should be an optional setting on the Field creation?

Checking $cookie-username is not secure

I don't think that checking for $cookie-username value is helping to secure anything. Cookies can be created by user (client-side). Even checking if user exists in database is not enough. One would have to check both username and password (but data source provided by Symphony cannot filter by password hash :(.

It is not a bug of Your extension, just a notice that maybe suggesting $cookie-username as a method of securing access is not the best idea :).

Symphony 2.6: Cookie handling is broken

Using Symphony 2.6, there are issues with the field's cookie handling:

  1. The user is logged out after having seen a page with an HTML Panel.
  2. The Cookie does not allow using "admin" type pages for an HTML panel. So probably the cookie is incorrect.

Fixing incompatability with parenthesis tabs

Parenthesis tabs expects fields to be labelled with a <label> element, whereas HTML panel creates labels wrapped in a <span>.

Changing lines 98-100 of field.html_panel.php to the following appears to allow the two extensions to play nicely together:

$label = new XMLElement('label', $this->get('label'));
$label->appendChild($container);
$wrapper->appendChild($label);

I suppose having a label element without a corresponding input might be bad practice, but it works nicely.

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.