Feature: Implement macros to be called from HTML / page contents #87
Labels
No labels
Component: User interface
Component: Wymeditor
Help wanted
Level: Difficult
Level: Easy
Level: Moderate
Pagetype: Festival
Pagetype: Mailinglist
Pagetype: Peer reviewed article
Pagetype: Text
Privacy GDPR AVG
status: has conflicts
Status: Needs changes
Status: Needs discussion
Status: Needs review
Status: Ready to merge
Status: Waiting for response
Type: Bug
Type: Enhancement
Type: Question
Usecase: De Stadsbron
Usecase: Koppelting
Usecase: MeetjeStad
Value: Coders
Value: Security
Value: Users
Value: Visitors
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
harmen/hypha#87
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Use case: in De Stadsbron we now can not easily distinguish between public/non public and published/not published pages This may lead to pages that stay unpublished.
Possible direction:
[list]: shows all pages that are available for the current user (= equal to current index)[list content-type=article published=no author=current-user]shows all my non-published articles[list published=no]shows all unpublished pages, not regarding content type.By placing these codes on a page, the list may be shown, like in Wordpress.
To be discussed & expanded.
etc.
[list content-type=article tag="westtangent"]Other idea after brainstorm: make index more versatile
use columns and classes and filters. All addressable through URL.
Need mockup.
[list content-type= article after-date="2018-10-01" before-date=today][list content-type=article date="2018-10"]for articles in october[list show-filter=content-type include=[article, page]]For an index with a filter that visitors can use for filtering per content-type, showing pages and articles.
From the Wordpress universe:
https://wordpress.org/plugins/display-posts-shortcode/
This seems like a good way to implement the ideas we had in #298. A "dossier" page can then be a normal text page where the "header" and "footer" would just be plain HTML and the main page list could be generated using such an escape tag. Similarly, the homepage could be a plain text page, with some of these tags that indicate "insert most recent three videos here", or "insert 10 most recent articles here", or maybe even "insert these pages here" (where pages would be identified by id or url maybe?). The latter might need a UI to easily select pages, so that might be more complex again...
The page selection for such a list would be more complex than the currently implemented tag index (which only shows pages with a single tags), since it could filter on datatype, tag, maybe date and have configurable sorting and pagination.
As for implementing this, I originally had the idea of making these lists a proper datatype that could be used by themselves as well, but with an "embeddable" view. Then, you could include these embeddable views in other pages by just referring to that defined page. This could happen either server-side, but maybe also client-side (by just matching special tags and replacing their contents with an AJAX-request).
Creating separate pages for these has the advantage of allowing a proper UI for selecting them (rather than just typing text or raw HTML directly), though I guess a wymeditor module for editing these special lines could also be added maybe. The downside of creating separate pages is that you get a bunch of extra pages, which makes things more heavy-handed.
An upside of interpreting these tags client-side could be that it is easier to preview the result of these tags while editing (probably not inside the wymeditor, but wymeditor does have a preview button as well I believe). The downside is more requests, latency and server load, probably.
So, I tend to make these not separate pages (just put the proper tags in a text page to generate a list) and then interpret them server-side.
As for interpreting these tags, this could be done when rendering a wymeditor-editable field specifically, but maybe it could also be done as a global post-processing hook over the generated DOM. This would allow these special tags to occur anywhere, including in the
hypha.html, which might also be valuable. It does mean these tags are rendered with fewer context (e.g. they won't necessarily have access to the page they were rendered in, for example).As for how these tags would look, there's a few thoughts:
Writing these as HTML/XML tags might be the most flexible in the backend, since all escaping etc. is handled automatically, you can search for and access data using DomDocument/XPath, etc. For users, this more tricky, since it requires going through the HTML source editor to change these (but maybe that is acceptable, since this is rather an advanced feature). E.g. something like:
Using XML also makes more complex, nested structures easier (on the backend, at least):
Writing these tags as text inside the normal editor could be an alternative. This makes it easier to edit these, but maybe also more fragile (easier to make a typo in the syntax). Depending on how unique the syntax is, it might be easier to accidentally trigger it as well, maybe even by unauthenticated visitors in comments.
e.g.:
Implementing something like this in text might require some good thought about the syntax and a proper, generic parser (to allow arbitrary attributes, maybe attributes with list values as well, etc.). One advantage of using HTML is that this part is builtin. An alternative could be to use some other existing syntax (e.g. JSON) that PHP can already parse.
e.g.:
Or more complex:
Today we discussed this a bit further.
For naming these "things that you can include on a page", we suggested: content generators, shortcodes (like Wordpress), element, block, section, macro, lookup, placeholder, blob. For now, we'll work with the term "Macro".
Some ideas on additional usecases for this
Note that something like "Showing related articles" is not really a macro at first glance, since you wouldl likely want to put that on every article, not only the ones where you manually include this macro code. However, that suggests another use for macros: Maybe you could globally config something like "On all pages with type=peer_reviewed_article, append the related_articles macro to the #pagefooter element". This would certainly be a later addition, though.
Some additional thoughts:
.phpand include that file), which increases performance when macros are not required. Alternatively, they could all be included and they could register themselves as available macros, or the macro name could refer to a class name (checking that they extend from some newHyphaMacroclass for safety).The basic version of this is implemented in #329 which I just merged, so I'm closing this. I moved the remaining improvements discussed here to #367.