Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enclosed shortcodes #129

Open
bobbingwide opened this issue Feb 2, 2015 · 12 comments
Open

Enclosed shortcodes #129

bobbingwide opened this issue Feb 2, 2015 · 12 comments

Comments

@bobbingwide
Copy link

Some shortcodes require the content to be enclosed between shortcode start and end tags.
It should be possible to identify these shortcodes using a mechanism other than using a labelled parameter of 'content'.

Conversely, it should be possible to identify shortcodes that DO NOT SUPPORT the $content parameter. So if I have manually created a shortcode like this

[my-shortcode]Some awesome inner content[/my-shortcode]

and my-shortcode does not support nested content, then my mistake should be reported to me.

This is related to issue #93.

Note: In my shortcode catalog I have a checkbox field labelled 'Enclosed content shortcode' where this information is registered. The value is displayed in the Information but is currently unused in the code.

@danielbachhuber
Copy link
Contributor

Yep, agree.

@eliot-akira
Copy link

On the topic of enclosed/nested shortcodes: I just discovered Shortcake - love the concept and implementation - and started to explore how to integrate my plugin's shortcodes - and I've got several nested ones. An example of a basic syntax is:

[loop type="post" count="3"]
  [field title]
  [field date]
[/loop]

I was able to register the parent shortcode, get an input form via Add Media with parameters and inner content as text area, and insert the generated result into the post. The rendered result in the visual editor is perfect, such a superior editing experience than seeing all those shortcodes raw.

However, when I click to edit the block, the inner content doesn't appear in the text area (it's blank).

Here's how I'm registering it:

shortcode_ui_register_for_shortcode(
  'loop',
  array(
    'label' => 'Loop',
    'listItemImage' => 'dashicons-share-alt',
    'attrs' => array(
      array(
        'label'       => 'Parameters',
        'attr'        => 'type',
        'type'        => 'select',
        'options'     => $types,
      ),
      array(
        'label' => 'Template',
        'attr'  => 'content',
        'type'  => 'textarea',
      ),
    ),
  )
);

I saved the post, but when I go to edit the inner content, the text area is still empty - and nothing in the Preview tab. It is displaying the result fine in the visual editor.

@eliot-akira
Copy link

I traced it down to: sui.utils.shortcodeViewConstructor.View.edit.

At the start of the function, variable shortcodeString in my case is [loop type="post"][field title][/loop]. After the regex, content = matches[3] is undefined. I tried the inner content without the shortcode: [loop type="post"]test[/loop] - ah, now the content is retrieved correctly and shows up in the textarea in Post Element Details.

So it seems that megaRegex could be adjusted to match the inner content including shortcodes? I'm afraid I'm not fluent enough in regular expressions to figure this out.

I realized this is the same issue as #126.

@cliffordp
Copy link

Some examples of how Shortcake can royally screw up manually-entered shortcodes (since Shortcake doesn't natively handle these scenarios properly):

Demo 1:

[row gap=false]
[col w=4]yupperoos![/col]
[col w=8]eight wide here, boss[/col]
[/row]

The inner_content preview is blank because it "fails" at the beginning of any opening bracket [.
If you were to click Shortcake's "Update" button, it would output [row gap=false][/row] -- lost all inner_content after the first [, which in this case was all the content.

Demo 2:

[row gap=false]
yes before
[col w=4]yupperoos![/col]
[col w=8]eight wide here, boss[/col]
no after
[/row]

The inner_content will display "yes before" because, again, it fails at the first [ sighting.
If you use Shortcake to edit [row] (e.g. to change gap=false to gap=true), it will wrongly change the entire output to [row gap=true]yes before[/row] -- lost all inner_content after the first [.

@cliffordp
Copy link

Ideally, I'd like to see Shortcake's previewer be smart enough to handle nested shortcodes with both parent and children shortcodes editable via UI (not just the parent with a free-form inner_content area that should contain all the manually-entered children shortcodes).

These more complex shortcodes are exactly what UIs are useful for. Instead, I find myself just registering shortcodes without tying into Shortcake or, if they do, returning blank if is_admin() because they don't look right without being inside a parent shortcode.

This has become my Number 1 issue with Shortcake. It's hard for me to say,

Use my awesome shortcodes. Only half of them have UI -- the easy half.
(And if you use it wrong, you'll lose a lot of content.)

I don't know the solution, but I'm hoping to bring more attention to this problem.

@danielbachhuber
Copy link
Contributor

Thanks for the additional details, @cliffordp.

Ideally, I'd like to see Shortcake's previewer be smart enough to handle nested shortcodes with both parent and children shortcodes editable via UI

Supporting editing interfaces for nested shortcodes is outside the scope of the project. However, Shortcake shouldn't be clobbering that data.

@cliffordp
Copy link

Glad we can at least agree that

Shortcake shouldn't be clobbering that data

👍

@khromov
Copy link
Contributor

khromov commented Sep 21, 2015

👍 want to see data mangling get fixed, very frustrating currently.

@westonruter
Copy link
Contributor

I think that support for nested views for shortcodes are the answer for how WordPress core will be able provide a UI similar to the many page builders out there, like Visual Composer. Consider shortcodes that represent rows and columns. This paired with the ability to drag-and-drop shortcodes (#51) will make this super compelling.

@stevenvachon
Copy link

Is anything being done about this?

@pingram3541
Copy link

@westonruter Yes and bundled with the customizer, the core will finally have a front end page builder provided by live shortcodes, widgets, menus and even theme/site options. This is exciting times.

@lkraav
Copy link

lkraav commented Dec 18, 2016

Yes and bundled with the customizer, the core will finally have a front end page builder provided by live shortcodes, widgets, menus and even theme/site options. This is exciting times.

Just watched @khromov's video introduction. Got to wondering where this particular issue is at 8 months later from last comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants