4

I am creating a Page in SDL Tridion that allows producers to modify the robots.txt file for our site on the fly without requiring a code deployment.

I have the following Schemas:

  • Robots that contains:

    • userAgentCollection (Embedded Schema)
    • sitemap (text)
    • modifiedDate (Date)
  • userAgentCollection (embedded schema) that contains:

    • userAgent (text)
    • disallow (Embedded Schema)
    • crawlDelay (text)
  • disallow (embedded schema) which contains:

    • Disallow (text)

I have a form that allows the user to add multiple user agents and each user agent can have multiple disallows.

My razor has the following code:

@model DD4T.ContentModel.IPage

# Modified @Model.MetadataFields["modifiedDate"].Value
@foreach(var userAgent in @Model.MetadataFields["userAgentCollection"].EmbeddedValues) 
{ 
    User-agent: @userAgent["userAgent"].Value
    foreach(var disallow in @userAgent["disallow"].EmbeddedValues) 
    {
        <span>Disallow:  </span>@disallow["Disallow"].Value<br />
    }
    <span>Crawl-delay:  </span>@userAgent["crawlDelay"].Value<br />
}
Sitemap: @Model.MetadataFields["sitemap"].Value

When it renders I get

# Modified 2013-11-20
User-agent: BingBot
Disallow: /c/noindex*
Crawl-delay: 1
User-agent: GoogleBot
Disallow: /foo/
Crawl-delay: 1
Sitemap: http://foo.com/sitemap.axd

But what I want is

# Modified 2013-11-20
User-agent: BingBot
Disallow: /c/noindex*
Disallow: /WCM/
Disallow: /FooToo/
Crawl-delay: 1
User-agent: GoogleBot
Disallow: /foo/
Crawl-delay: 1
Sitemap: http://foo.com/sitemap.axd

Only the first item in the disallow collection for each useragent is getting rendered.

Can anyone see what is wrong?

| improve this question | | | | |
  • @Rhonda to properly format your code indent it with 4 spaces, see also tridion.stackexchange.com/help/formatting and tridion.stackexchange.com/editing-help#code, it is not just the code that is messy, your question seems to start with 0 down vote favorite? – Bart Koopman Nov 21 '13 at 17:21
  • @Rhonda I see you copied your question from stackoverflow, please don't do that. You can flag it for moderator attention and ask it to be migrated in the future. Or just close it there when you want to post it elsewhere. I have indented your code and formatted the rest, please have a look to what I did and adjust where needed. – Bart Koopman Nov 21 '13 at 17:55
  • Not that this is related to your issue but is HTML allowed in a robots.txt file? – Rob Stevenson-Leggett Nov 22 '13 at 11:08
3

Not a direct answer to your question, but as your disallow embedded Schema only seems to contain a single text field, I would recommend to remove the Embeddable Schema and change that in a Multiple Value Text Field.

Then you could also just loop over Field.Values, although I agree it is a bit strange that your code doesn't seem to work. At first look I would expect that to be correct.

| improve this answer | | | | |
0

@Rhonda: Can you please check in your broker database, if you are able to find all the values for the "Disallow" attribute. If not the issue could be in your Component Template,the number of linked level might be less, try to increase the same.

| improve this answer | | | | |
  • I'm not sure the LinkLevel is to blame here, since it only impacts component links, not embedded fields. – Quirijn Nov 22 '13 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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