Skip to content

Conversation

PeterNerlich
Copy link
Contributor

@PeterNerlich PeterNerlich commented Jul 7, 2025

Short description

This PR drafts a shortcodes implementation as an alternative to use internal links, contact cards etc. in content. This removes the problem of having to keep track of and update information scattered among many content objects.

To test it, add something like this to a page:  [page 1 "this page"] or [contact 3] (see the added documentation of the shortcodes for more details) and look at the API response (e.g. /api/v3/augsburg/de/page/?id=1)

Proposed changes

  • Add shortcodes as new dependency
  • Add the integreat_cms.cms.utils.shortcodes module to house all shortcodes and their processing facilities
  • Add a content filter expand_shortcodes to django that returns the content passed to it with all shortcodes replaced by their expanded versions
  • For reference, implement the page shortcode to link to pages and the contact shortcode to render contact cards

TODO: (in a future PR?)

  • More shortcodes:
    • More content objects like locations or events
    • Images/icons
  • Adjust TinyMCE to insert shortcodes instead of raw html whereever possible
  • Adjust TinyMCE to render shortcodes in some way (but not overwrite them in the content)
  • Handle page preview
    currently fully client side, need to decide on strategy: send content to backend to process and check or (partial?) re-implementation in JS
  • We might want to limit the page and contact shortcodes to require explicitly stating the correct region slug if not referring to a target belonging to the region of the content object that is being processed
  • Also required by the above step, the strategy to handle and pass context information to shortcode handlers needs to be improved

Side effects

  • API calls will now take a bit longer if many shortcodes are in the content to be handed out
  • More opportunity to mess up when answering requests from end users
    • I wrapped content processing into a try except block:
    • If any shortcode fails, the original content will be delivered verbatim, without any of the shortcodes replaced

Faithfulness to issue description and design

There are no intended deviations from the issue and design.

Resolved issues

Part of #3745


Pull Request Review Guidelines

@JoeyStk JoeyStk self-requested a review August 11, 2025 10:09
@JoeyStk JoeyStk self-assigned this Aug 11, 2025
@JoeyStk JoeyStk removed their request for review August 26, 2025 11:27
@JoeyStk JoeyStk removed their assignment Aug 26, 2025
@hannaseithe hannaseithe self-assigned this Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants