2

I have a Schema A having a Component link field where three other Schemas have been selected in the Allowed Schema pane.

Now a CT has been built to render the fields from A. While using SiteEdit to change the Component link field all the Components created with Schema A plus the Components created using Schemas in the Allowed Schema are available to drop in the Component link fields.

As the CT is not rendering any of the fields from the Allowed Schema, it's giving a runtime error which is evident. Now is there any way to overcome this issue so that the fields (if not available) can be bypassed without modifying the Allowed Schema?

1
  • I'm unable to follow your exact question, could you edit it and add some more detail like perhaps the source of your Component Template (only relevant parts) and some screenshots of the Schema? Commented Oct 21, 2013 at 11:58

2 Answers 2

3

What you need to do is to evaluate in your template whether those fields are available or not and act accordingly. If the logic becomes to complex, you might wanna split the code into several TBBs, like "Check Link Type", that will give you what time of "Linked Component" is used (its Schema, for example), and then you take it from there.

You can also always use DWT syntax for validation, or even a custom Source function, something like:

<!-- TempalteBeginIf cond="GetLinkType(Component.Fields.link) == 'A' " -->
<h1>YOUR HTML IN CASE LINK IS TO SCHEMA A</h1>
<!-- TemplateEndIf -->
<!-- TempalteBeginIf cond="GetLinkType(Component.Fields.link) == 'B' " -->
<h1>YOUR HTML IN CASE LINK IS TO SCHEMA B</h1>
<!-- TemplateEndIf -->

Note: in the code above the GetLinkType function is your custom source dwt funciton.

And remember, that when you say: "As the CT is not rendering any of the fields from the Allowed Schema, it's giving a runtime error which is evident. " , that is something your Template should take care of, I mean, you should handle those scenarios, since your design allows those types of links in your content type, hence your template code should be able to deal with them to.

2
  • Yes Jaime, you are totally correct that it should have been taken care in templates if u have allowed the schemas. I was just wondering if anything can be done without changing the template and schema list which I understand now is not correct thought.
    – user734
    Commented Oct 21, 2013 at 13:30
  • Not that I know. Normally if there's an error in a template, you will have to fix it in the template itself. Imagine someone accesses a field in a template without checking whether it exists or not... or someone changed the xml name of a field, you'll need to "update" your template accordingly. Commented Oct 21, 2013 at 14:39
5

One solution could be to use event system to parse out the component links entered into the field and check if the links are created using an allowed schema, here would be the steps:

1) on save - check rtf field for component links

2) for each component link check the schema used

3) custom logic - check the rule of schema / link is allowed

4) warn / or allow saving

Note: This solution is more aimed at preventing the saving of these links, rather than stopping their configuration.

3
  • 1
    Wouldn't it be easier to remove the "Allowed Schema" from the field itself... Commented Oct 21, 2013 at 17:33
  • i'm talking about if the user is trying to snif component links in the RTF @JaimeSantosAlcón
    – johnwinter
    Commented Oct 23, 2013 at 18:47
  • then you have a point :) Commented Oct 23, 2013 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.