How can I combine placeholder and template in my config?

Most of the elements in my schema are inserted with placeholders, e.g.

<x:node match="para">
  <x:role>paragraph</x:role>
  <x:placeholder>New {name}</x:placeholder>
</x:node>

When the user inserts a para, they see a red New para highlighted and typing in the paragraph will replace this. It's nice.

I have some elements which require a couple of attributes to be supplied; they're fixed in the schema but the Xopus editor does not force them when a user creates a new element. I can get around this by using a template, e.g.

<x:node match="code">
  <x:templates>
    <x:template formatted="Y" xml:space="preserve">
    </x:template>
  </x:templates>
</x:node>

Ideally I would include a placeholder in the template and have the user see New code when they inserted this element. Unfortunately the content of a placeholder is inserted as ordinary text, so it isn't replaced when the user starts typing in the element.

With no placeholder the element has a tendency to disappear completely, and the user has to be very careful positioning the cursor.

13 Replies Latest Replies: 16 Oct 2018 5:50 AM by Trevor Nicholls < 1   2   3  >
  • To clarify the last sentence above, if the user inserts a code element and starts typing, the code element is replaced by the text they type. The only way to insert a code element is to switch to visible tag view, insert the element, click within the code element to unselect it, and then type. When I explain this to a user their first response is going to be "that's ridiculous", and it is.
  • In reply to Trevor Nicholls:

    Hi Trevor!

    I believe you defined placeholder inside template and that is why it is shown as regular text.

    <x:node match="code">
    <x:templates>
    <x:template formatted="Y" xml:space="preserve">
    <x:placeholder>New {name}</x:placeholder>
    </x:template>
    </x:templates>
    </x:node>

    If you define it on node level it should work as expected:

    <x:node match="code">
    <x:templates>
    <x:template formatted="Y" xml:space="preserve">
    </x:template>
    </x:templates>
    <x:placeholder>New {name}</x:placeholder>
    </x:node>
     

    Please also compare to the way we implemented codeblock element in this example.

  • In reply to Oleksandr Fedan:

    Hi, thanks for looking at this

    I tried with the placeholder outside the templates first, and only moved it inside the templates when it didn't work.

    What happens when it is defined on the node is that New code appears, and disappears when the user types, but the code element disappears too and the user's input has replaced it with ordinary text.

  • In reply to Oleksandr Fedan:

    In the foregoing, "code" is an inline element for words or expressions embedded in a paragraph. We have an element equivalent to your "codeblock", which in our schema is named "fragment". A placeholder on the node for fragment behaves differently: when I insert a new fragment several lines open up and "new fragment" is displayed right aligned on the last line. The characters "new fragment" disappear as soon as I start typing, but lots of trailing tabs and spaces are left in the element when I click out of it.

    Your codeblock is much simpler than ours, and in fact if we could get the right behaviour we wouldn't need the template at all. I can't check your fiddle because it's not possible to save the xml and check whether or not newlines are preserved in the codeblock - when we were developing under Xopus 4.something we found that despite the xml:space="preserve" in our schema all the text in our fragments was being collapsed when the document was saved. Hence some extra engineering. Maybe that's unnecessary now.

  • In reply to Trevor Nicholls:

    if the placeholder is shown, the element disappears when user starts typing, but it shows when you activate tags in view, it means the element is there.

    I don't know how your xsl looks like, but maybe you should look into the xsl instructions that process the code element. Wrap the content in a <span> element and give it some visibility using css, changing the font or something like that. Hope it helps.
< 1   2   3  >
Related