I want to create a custom content block in Sitefinity so I can wrap an tag around it and pick up my CSS.
I created a custom widget, but I'm not sure how to make it a content block. I cannot find documentation on this, but I'm sure it is a common occurrence. Basically, I want a drag out content block that does this:
<aside>
[code for content block]
</aside>
I don't know how to generate the [content block] code in .net. I am new to .net development. I am using VB but can use C#.
Any help would be greatly appreciated. Thank you.
Maria
You can create a custom Layout Control which can be used in conjunction with other controls, such as Content Blocks.
To create a Layout control, open your project in Visual Studio and create a new control (.ascx) file in the WebApp project. I normally put mine in a ~/LayoutControls folder which I create. In that control file, enter something like:
<div runat="server" class="sf_cols">
<aside>
<div id="Div1" runat="server" class="sf_colsIn"></div>
</aside>
</div>
You'll notice that besides the markup you want, the aside tag, I have two other divs with some specifics. These are needed so Sitefinity can treat this as a control, and be able to dynamically inject content into it.
A div with class sf_cols is common to all controls and the div with class sf_colsIn (id="Div1") is where control you drop onto the layout control will go. So there is an outer wrapper div, your markup, and an inner div. It's the inner div where your content will go.
Save your file, compile the project, then register the control in Sitefinity.
To do that, login to the backend then navigate to Administration | Settings | Advanced Settings | Toolboxes | Toolboxes | PageLayouts | Sections. I normally add a new section with these properties:
name=Custom,Title=Custom,Description=Custom Layouts,Global resourceClassId=PageResources
Then select your new section, select Tools, then Create New. The Name, Title, Description are whatever makes sense for you control. The Control CLR Type should be Telerik.Sitefinity.Web.UI.LayoutControl, Telerik.Sitefinity and the Layout Template should be the path to your ascx file, i.e. ~/LayoutControls/AsideBlock.ascx. The other properties can have the default values (most are just blank). Then Save.
Now when you are editing a page, click the 'Layout' button in the right hand column and you will see a 'Custom' Section which contains your control. Drag it onto the page, then go back to 'Content' editing (using the button in the right hand column). You will see your layout control and drop a content block onto it.
Add content normally. When the page renders, the content will be wrapped in the aside tag.
the easiest way to do this is with an external template for the content block. The template you want is ContentBlock.ascx and is in the SDK.
Copy this file to your project then add the wrapping tags around the contentHtml literal control (which renders the actual content of the control).
Then open the Advanced settings of the content block widget you want to use this template and specifiy the LayoutTemplatePath. It should have a default value of something like "~/SFRes/Telerik.Sitefinity.Resources.Templates.Backend.GenericContent.ContentBlock.ascx".
Simply change this to the virtual path to the template you created, then save and publish the page.
The content block will render with your template instead of the default one, with any markup you add.
I hope this is helpful!
I'm going to create a more detailed blog post that walks through this process and will link it here when I'm done. thank you for the inspiration!
Related
According to Create.js' integration guide, it should be possible to create editable collections of blocks.
Relationships between entities allow you to communicate structured
content to Create.js, which will turn them into Backbone collections.
For example, to annotate a list of blog posts:
<div about="http://example.net/blog/" rel="dcTerms:hasPart">
<div about="http://example.net/my-post">...</div>
<div about="http://example.net/second-post">...</div>
</div>
This dcTerms:hasPart doesn't seem to be present explicitly in Create.js; it's probably from a vocabulary. How can one show to Create.js that this content is a collection and make it show the "Add" button? In my case, I simply have sections which contain <h2>, <h3> and <article>s.
EDIT: Using rel="hasPart" in my <section>, the button appears. Problem is Create always uses the first element as a template. In this case, it uses my <h2> as template, which is not what I intended. So my question now would be how to trigger the "add" event in my section?
Hackish solution:
Using javascript, I created a new section or article in the DOM, then restarted Create calling $('body').midgardCreate({...}) again. Create will now recognize the new block. When I edit some fields in the block, the "Save" button is enabled and I can submit the new block.
I have used Sitecore field renderer for one of my page to be edited in the Sitecore page editor. That page includes an image which needs to be reference from Sitecore media library.
So I insert the image control into the markup of the Sitecore field renderer as follows
<img id="imgBusinessAdFeatues" class="classifiedImageSamples" src="~/media/Images/What is a Business Account/businessAdFeatures.ashx" alt="Business Ad with Features" />
“~/media/Images/What is a Business Account/businessAdFeatures.ashx” is the path to the image that stored in Sitecore media folder.
Now the image is rendered properly inside the page, but when I tried to edit that image (upload a new image) using Sitecore page editor it’s not allow me.
Is there any way to make the image editable (Upload a new image) when I open that page in Sitecore page editor?
Thanks
Thank you for the ideas.
But my problem is little bit different. I have Sitecore field renderer in in my sample page.
<sc:FieldRenderer ID="frTestPage" runat="server" />
From the code behind on that page, I bind a Sitecore item as follows.
frTestPage.Item = DatabaseManager.MasterDatabase.GetItem(“itemID1”);
frTestPage.FieldName = "Content";
In the item that I’m binding to the field renderer, it has richtextbox field name “Content”.
Within that “Content” field I have inserted my markup to be render to the page. So that markup consist of following img tag and other relevant HTML.
<img id="imgBusinessAdFeatues" class="classifiedImageSamples" src="~/media/Images/What is a Business Account/businessAdFeatures.ashx" alt="Business Ad with Features" />
So how can I give the image src path correctly which reference to an image in Sitecore media library.
It's wrong to use hardcoded path for images:
You can see all parameters here.
If you use XSLT to render your images, you can apply the parameters on the sc:image directly:
<sc:image field="MyImage" width="150" height="100" bc="ffffff"/>
If you use UserControls (.ascx) to render your images, you can register the following tagprefix to access sc:Image and sc:FieldRenderer:
<%# Register TagPrefix="sc" Namespace="Sitecore.Web.UI.WebControls" Assembly="Sitecore.Kernel" %>
You can use Edit(Page Editor), then More -> Insert Image, see:
Also, to have a more edit options you can use "Edit e related Item"
Drupal 6.28:
I'm re-theming a particular section of a site and the new design called for five pages to be displayed as five tabs on one page with the appropriate one shown when either clicking on the tab itself or in an expanded menu to the left.
I created all that in html and jquery so that I could deep-link the tabs, ie... someone can click on any menu link and hit the page with the appropriate tab open instead of having to go to the master page and then click the appropriate tab. (using location.hash)
This is all working fine, but the last tab is to house content that currently is a view set as a block.
What is the best way to pull that view/block into the html div I have set aside for that specific content?
I have used this great snippet before:
<?php
$block = module_invoke('block', 'block', 'view', '15');
print $block['content'];
?>
which allows one to place any block anywhere, but with a view with a display set as a block, I'm not having any luck invoking that view. Also, I'd had to have to use "php" instead of 'full html' on the node since it's just a snippet but as it's not currently working, it probably doesn't matter.
so, I'm trying to figure out how to have something like this:
<!-- all the other tabs content-->
<div id="fifthTab">
all the content from the view which is set to 'display like a block'
</div>
I'm fairly new to Drupal and not even sure if I create a page display how I would call that data anyway.
So my html structure is:
MAIN PAGE LINK
-sub link/tab 1/default
-sub link/tab 2
-sub link/tab3
-sub link/tab4
-sub link/tab5
So if someone either clicks on on the sub link/tab 5 in the left nav or clicks on the actual tab 5 or enters the url xxx/#tab5, the appropriate tab is show, the rest hidden. That's all working great, I just cant get the view content to show in that tab5.
so a page template based on the url is the easiest. The variable $content is just placed in the last tab and all other html content for that specific page is just put in the template.
At least this way, as docs are added, it's still dynamic and the static info is easy to edit if needed.
Just in case something similar comes up for someone else.
As you probably already know, I'm working hard on some XPM templates with Razor. I've ran into another issue, this time concerning rendering components inside templates in order to make them siteEditable.
The following I'm not sure about. I've got a component which has a title field called "Title", and multivalue componentlink fields which consists of components with a title, description and image. Let's call this one "Linked USP" for now.
Currently this is being rendered by a Template called 'Page Banner', and it just iterates over fields with some If-loops to determine it's presentation, especially for the Title. In order for XPM to work, this template needs to render the component presentation of "Linked USP". So we've created a template called "[XPM] USP ITEM". - this Component template has the 'enable content editing TBB" added to it.
Now the issue arises when I want to make the Title Editable as well. Sounds straightforward, no? Not really - because when the parent template has got a "enable for content editing" TBB added, it will add <span> tags to all editable fields but the templates that gets invoked inside this template will also have <span> -tags, effectively bloating the html and making it impossible to edit the fields inside the RenderComponentPresentation because of duplicate <span>s.
Some code for your fun and to illustrate my issue:
<h1>#RenderComponentField("Title", 0)</h1>
#Foreach(var linkedUSP in Fields.USPS){
#RenderComponentPresentation("linkedUSP.ID", "tcm:10-1076-32")
}
This template has an enable Content edit TBB added.
now, for the RCP mentioned above, inside its [XPM] template:
<div class="title">#RenderComponentField("Title", 0)</div>
<p>#RenderComponentField("Description", 0)</p>
<tcdl:ComponentField name="img">
<img src="#img" alt="img.MetaData.alt">
</tcdl:ComponentField>
This one ALSO has the "Enable Content Edit" TBB added. On the front end this happens:
<div class="title"><span><span>Men</span></span></div>
Because the parent template also adds spans to the field.
So my question: how do i solve this? The Title field mentioned above has to be inside the parent template, but I can't create a special template for it becuase it is no component link. I can't get the TBB out of my RCP template, because it won't be editable that way. Interesting huh?
Can't I disable the spans inside template builder somehow?
Using the Orchard admin I created a new Content Part called 'Spotlight Wrapper' with 3 HTML fields. I then created a Content Type Called 'Template 1' and assigned 'Spotlight Wrapper' to it. I then created a new 'Template 1' content item called 'Home Page'. I then created a file called Fileds_Contrib.Html-Spotlight Wrapper.cshtml to wrap each HTML field in the 'Spotlight Wrapper' with an and this is working. I have now added:
<Place Parts_SpotlightWrapper="Content:before;Wrapper=Parts_SpotlightWrapper" />
And created :
Views\Parts.SpotlightWrapper.cshtml
in an attempt to wrap the entire 'Spotlight Wrapper' Content Part in a but cannot seem to get it to work?
You declared a wrapper which I guess would lead to circular reference, as you try to wrap the Parts_SpotlightWrapper shape with itself. Wrappers are just separate pieces of Razor (cshtml) code that act as a parent for a given shape.
To achieve the behavior you want you should create a separate .cshtml file (eg. MyWrapper.cshtml) containing the necessary wrapper HTML code and attach it to your existing part like this:
<Place Parts_SpotlightWrapper="Content:before;Wrapper=MyWrapper" />
The wrapper code could look eg. like this:
<ul>
#Display(Model.Child)
</ul>
Btw - Try to look how it's done in Orchard.Widgets. There are two wrappers Widget.Wrapper and Widget.ControlWrapper that wrap the Widget shape. Declarations of those are not inside the Placement.info file (as you did), but hardcoded in Shapes.cs shape definition, though the final effect is perfectly the same. The technique with the Placement.info was just introduced later as a shortcut.
HTH