Querying Sitecore Content Item Data Fields With Spaces in Data Field Name - sitecore

Please be gentle...I'm very new to Sitecore development.
So the following returns the value from any data field associated with a content item...as long as the data field name has no spaces in it
#foreach($item in $genie.QueryPageItems("/sitecore/content/Sparklev2/articles/*"))
$item.Name - $item.Copyright - $item.Body Tag Css
#end
and the method it is calling (written by another developer):
public List<PageItem> QueryPageItems(string query){
return (from item in Sitecore.Context.Database.SelectItems(query).ToList<Item>() select new PageItem(item)).ToList<PageItem>();
}
The above returns the name and the copyright fine, but not the body tag css values. I have wrapped body tag css in everything I could think of but cannot make this work. Am I missing something or is this just not possilbe

You need to escape special characters and space.
/sitecore/content/#Sparkle V2#/articles/*
On a separate note; it's gonna perform donkeys. But escaping is your answer.

Related

In ColdFusion do I add to the title tag from a document that is "Included"?

I have an index page that calls several includes using variables. Part of my site has an inventory section. I would like to insert the name of the inventory item into the title tag. From the index, I can tailor the title tag in the header to show the section and categories, but since the query for the individual item is in the included file, that variable doesn't exist yet when the index comes up. I tried to use the cfhtmlhead from the inventory page, but it neither adds to nor replaces the title that is called in the index.cfm page. Here is my code, but it doesn't work.
<cfhtmlhead text="<title>xxxx</title>"></cfhtmlhead>
I guess, I could pass the inventory item name in the URL, but most items have spaces in them and then I have to deal with that too.
Thanks,
Kirk
cfhtmlhead doesn't seem to work when it is in cfincludes

Use the title= HTML attribute with RMarkdown

I am trying to understand if it is possible to insert the HTML title= attribute (not necessarily inside an <abbr> tag) within an RMarkdown document (e.g. a blog post written through blogdown)
From W3C: the title attribute specifies extra information about an element. The information is most often shown as a tooltip text when the mouse moves over the element.
The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.
Couldn't find anything regarding using in in RMarkdown tho
You can write raw HTML in Markdown. However, if you are using Hugo >= v0.60.0, raw HTML will be ignored by default. You need to set an option in your config file to enable it:
[markup.goldmark.renderer]
unsafe= true

How do I get the value of a WFFM field as a tag and output it in a Sitecore DMS report?

If I create a Web Forms For Marketers form with Analytics enabled I can choose to add each field as a tag to a Visitor. I can't see how to configure which tag they should be added to, or even what the tag is called by default (I'm assuming a tag with the field name is created).
I'd also like to know how to retrieve the tag data in a visit report (i.e. the one you'd get if you double clicked on a form submission in the Form Reports dialogue). I can see how to access plenty of inbuilt tags, but I can't find out how to fill these specifically from the form, and I cant see any fields in the report designer representing the field names I have.
Question 1: How to set the name of the tag
If you set the "Tag" checkbox on the form field, the Item Name (=field name) of the form field is used as tag name.
If you have database access, you can check the "VisitorTags" table on the analytics database to see which tags are written and how they are called.
Question 2: Retrieve Tag data in visit reports
In the VisitDetail report, the following inbuilt tags will be displayed if set:
Email
First Name
Second Name
Company
Organization
Full Name
StateProvince
Name your form fields accordingly and the values will be used in the report out of the box.
If you want to use custom tags in reports, have a look at the .mrt files in /sitecore/shell/Applications/Reports/. You will have to extend the report to use your own tags.
Example: Adding a custom tag to the VisitDetail report.
Extend the SQL Query to fetch tags in the /sitecore/system/Settings/Analytics/Reports SQL Queries/Visits Visitor Tags item. Add the line
, MAX(CASE WHEN [TagName] = 'SomeCustomTag' THEN [TagValue] ELSE NULL END) [SomeCustomTag]
Extend the VisitDetail.mrt, add a column with value SomeCustomTag to the VisitorTags section just like the predefined tags.
Use the value of your custom tag inside the report text by using {Visit.VisitorTagsRelation.SomeCustomTag}
I use a text editor to edit the .mrt files, but you can probably also do it in Reports Designer.

droplink and treelist values in sitecore search

How to get droplink and treelist values in sitecore search .
Below are my code and config file . But when i am searching based on droplink and treelist value its not coming in search result .
var fquery = new FullTextQuery(search);
SearchHits searchHits = sc.Search(fquery, int.MaxValue);
return searchHits.FetchResults(0, int.MaxValue).Select(r => r.GetObject()).ToList();
config file entry .
I am not sure if i have to parse them or something else . Looking forward for help.
You don't say which version of Sitecore you're using, but speaking as someone who works with v6.6:
ID-based fields, like TreeList store GUIDs in the Sitecore database. At index time, Sitecore parses these into ShortID format and forces it to lower case. So the Lucene index entry actually contains a lowercase GUID with no curly braces or hyphens.
Chances are, your text-based query is not going to contain text that will match this.
I tend to use a Term based BooleanQuery object to match ID-based fields. Something like:
BooleanQuery query = new BooleanQuery();
query.Add(new TermQuery(new Term("myfieldname", ShortID.Encode(myGuidToMatch).ToLowerInvariant())), BooleanClause.Occur.MUST);
Note that the field name you want to query should be in lower case, as Sitecore / Lucene generally works in lower case.
You may find the code and UI example in this blog post helpful to see an example of building queries against ID-based fields:
http://jermdavis.wordpress.com/2014/06/09/faceted-search-in-sitecore-6-6/
If you want to be able to match the values contained in these fields from a free text type of search box, then you will have to pre-process the values from these ID-based fields before they are indexed.
Sitecore and Lucene allow for the idea of "computed fields" in your index - basically you can configure the indexing process to run bits of your own code in order to process data at index time, and to create new Lucene index fields from the results of your code.
This blog post of mine gives an example of a computed field:
http://jermdavis.wordpress.com/2014/05/05/using-dms-profile-cards-as-search-metadata/
That example is not doing what you want - but it does talk about how you might configure one of these custom fields.
You'd probably want your custom field code to:
Get the raw value of the ID-based field
Load the item that this ID points to
Process that item to turn it into the pattern of text you want to be indexed
Return this text, to be saved into the computed field in Lucene
With that done, you should find that your index will contain the text associated with your ID field(s). And hence you should be able to match it with a text-based query.
-- EDITED TO ADD --
More detail on creating computed index items:
Sitecore 6.6 doesn't directly support computed fields in your Lucene indexes. To get them you can make use of the Advanced Database Crawler - which is part of the Sitecore SearchContrib project available on GitHub: https://github.com/sitecorian/SitecoreSearchContrib
There are assorted blog posts about on getting started with this code.
[NB: In Sitecore 7.x I believe this behaviour has migrated into the core of Sitecore. However I think they changed the names of stuff. Details of that are available via google - things like Upgrading sitecore 6.6 index configuration to sitecore 7 (using ComputedFields) for example]
The code for a dynamic field to turn something ID-based into text might look like:
public class IndexIDField : BaseDynamicField
{
public override string ResolveValue(Sitecore.Data.Items.Item item)
{
Field fld = item.Fields["FieldYouAreInterestedIn"];
if (fld != null && !string.IsNullOrWhiteSpace(fld.Value))
{
string[] ids = fld.Value.Split('|');
StringBuilder text = new StringBuilder();
foreach (string id in ids)
{
Item relatedItem = item.Database.GetItem(id);
if (relatedItem != null)
{
text.Append(relatedItem.DisplayName);
text.Append(" ");
}
}
return text.ToString();
}
return null;
}
}
This is extracting the appropriate field from the context item that's being passed in. If it exists and is not empty, it splits it by "|" to get a list of all the IDs stored in this field. Then for each one it tries to load it. Note use of the appropriate database specified by the input item - Sitecore.Context.Database will point to Core at this point, and you won't find your items there. Finally, if we get back a valid item from the ID, we append its display name to our text to be indexed. You could use other fields than Display Name - depending on what makes sense in your solution.
With that code added to your solution you need to ensure it's called at index build time. The default config for the Advanced Database Crawler includes a config element for dynamic fields. (And again, SC7.x will have something similar but I don't know the names off the top of my head) You need to add your type to the configuration for dynamic fields. Snipping out all the extraneous bits from the default config:
<configuration xmlns:x="http://www.sitecore.net/xmlconfig/">
<sitecore>
<!-- snip -->
<search>
<!-- snip -->
<crawlers>
<demo type="scSearchContrib.Crawler.Crawlers.AdvancedDatabaseCrawler,scSearchContrib.Crawler">
<!-- snip -->
<dynamicFields hint="raw:AddDynamicFields">
<!-- snip -->
<dynamicField type="YourNamespace.IndexIDField,YourDLL" name="_myfieldname" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" />
</dynamicFields>
<!-- snip -->
</demo>
</crawlers>
</search>
</sitecore>
</configuration>
That sets up a new field called "_myfieldname" with sensible options for indexing text.
Rebuild your search index, and you should find your free text queries will match the appropriate items. Testing this basic setup on an instance of SC6.6, I get hits with some test data I happened to have lying around. If I search my computed column for "blue" I get only rows which were tagged with a metadata item that had "blue" in its name:

Sitecore: How to access same field name in different sections

I have data template dt1 in sitecore that has the field "header" in section "data".
I also have data template dt2 that has the field "header" in section "portal"
Finally I have data template dt3 that uses both dt1 and dt2 as base templates.
How can I, in xslt, find the content of portal/header?
In my code, when I write <sc:text field="header" />, I get the content of data/header (since this node comes first).
I know how to do this in .net, but I need to use xslt.
/callprat
I found a way around this in .Net on a project I was working on. One of the templates that the client had set up had "Buckets" which had different field sections, but the fields within were the same between buckets. I used LINQ to group the fields by Section name, then dealt with each grouping of fields.
var sections = currentItem.Fields.GroupBy(field => field.Section);
foreach (var section in sections)
{
if (section.Key.StartsWith("Bucket"))
{
buckets.Add(new Bucket(section)); //I made a bucket item,
//and passed each IGrouping<Field> to it
}
}
item.Fields.Where(field => field.Section.ToUpper() == "META DATA" &&
field.DisplayName.ToUpper() == "TITLE").First().Value;
You can't.
And frankly I don't know of any supported way to do it from .NET either.
This, straight out of the Data Definition Reference, section 2.1.1
2.1.1 Data Template Fields
A data template field defines the user
interface control and other properties
that influence how the field behaves
in the Content Editor and Page Editor.
For more information about fields, see
Chapter 4, The Template Field.
Note When defining field names, ensure
that they are unique even between
field sections. Both XSLT and .NET
code use field names alone, without
reference to sections, to extract
content from fields.
You can reference fields by their IDs:
C#:
string value = item["{00000000-0000-0000-000000000000}"]
or
Field field = item.Fields["{00000000-0000-0000-000000000000}"]
I haven't tried this, but I think it'll work in XSLT as well:
<sc:text field="{00000000-0000-0000-000000000000}" />