Customizing Containable Content in Orchard CMS - list

I am currently trying to understand a bit more about how Orchard handles Lists of Custom Content Types and I have run into a bit of an issue.
I created a Content Type named Story, which has the following parts:
Body
Common
Containable
Route
I created a list that holds these items, and all I am attempting to do is style them in such a way:
Story Title
Story Description (Basically a truncated version of the body?)
However, I cannot seem to figure out how to do the following:
Get the Title to actually appear (Currently all that appears is the body and a more link)
Remove the "more" link (and change this to be the actual Title)
I have looked into changing the Placement.info, and have looked all over in an attempt to find where the "more" link is added in each of the items. Any help would be greatly appreciated.

I finally managed to figure it out - Thanks to the Designer Tools Module, which made it very simple to go look into what was going on behind the scenes during Page Generation.
Basically - all that was necessary to accomplish this was to make some minor changes to the Parts.Common.Body.Summary.cshtml file. (found via ../Core/Common/Views/)
Which initially resembles the following:
#{
[~.ContentItem] contentItem = Model.ContentPart.ContentItem;
string bodyHtml = Model.Html.ToString();
var body = new HtmlString(Html.Excerpt(bodyHtml, 200).ToString()
.Replace(Environment.NewLine,"</p>"+Environment.NewLine+"<p>"));
}
<p>#body #Html.ItemDisplayLink(T("more").ToString(), contentItem)</p>
however by making a few changes (by using the Designer Tools) I change it into the following:
#{
[~.ContentItem] contentItem = Model.ContentPart.ContentItem;
string bodyHtml = Model.Html.ToString();
string title = Model.ContentPart.ContentItem.RoutePart.Title;
string summary = Html.Excerpt(bodyHtml, 100) + "...";
}
<div class='story'>
<p>
#Html.ItemDisplayLink(title, contentItem)
</p>
<summary>
#summary
</summary>
</div>
Although it could easily be shortened a bit - It does make the styling quite a big easier to handle. Anyways - I hope this helps :)

Alternately you can use the placement.info file in your theme assign different fields to your Summary and Detail views. It's much simplier.
http://orchardproject.net/docs/Understanding-placement-info.ashx
But, I used the same method you did till I discovered the .info file as well. It works and gives you a good understanding of how the system works, but the placement.info file seems easier.
Also, you probably don't want to be editing the view files in Core. I think your meant to override views in your theme directory.

Related

Customising the Quick Info Section in the Content Editor of Sitecore

Is it possible to customise the quick info section in the content editor to show additional information about the item?
Thanks
I think this would be quite tricky. If you look at Sitecore.Shell.Applications.ContentManager.Editor (in Sitecore.Client.dll), you'll see there is a RenderQuickInfo method. The HTML gets pieced together manually and is added to an EditorFormatter object as a literal control. All the classes involved are tightly integrated in to the application - there's no easily identifiable customisation point.
There are some pipelines associated with the rendering of the Content Editor,
renderContentEditor
getContentEditorFields
getContentEditorSkin
But I don't think these will provide an easy way in.
In general, I always think that if Sitecore haven't made part of the application easily customizable, then they probably did it on purpose.
One option could be a more js approach. The whole of the content editor is in the dom, albeit rather nested. It's slightly different but highlights the concept (http://blog.boro2g.co.uk/ever-edited-sitecore-web-db-mistake/).
I'd suggest if you use the example below in anger you make the xpath better - this was simply stolen from chrome dev tools.
As an example: with the following script pasted into the content manager.aspx file you can access some of the elements:
<script type="text/javascript">
window.onload=function(){
var text = getElementByXpath('//*[#id="EditorPanel"]/table/tbody/tr/td/table/tbody/tr[2]/td[1]');
if (text) {
text.innerText = "hi";
} else {
}
};
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
</script>
Which then allows you to update text (see screenshot):
quickinfo says hi

django - ckeditor bug renders text/string in raw html format

am using django ckeditor. Any text/content entered into its editor renders raw html output on the webpage.
for ex: this is rendered output of ckeditor field (RichTextField) on a webpage;
<p><span style="color:rgb(0, 0, 0)">this is a test file ’s forces durin</span><span style="color:rgb(0, 0, 0)">galla’s good test is one that fails Thereafter, never to fail in real environment. </span></p>
I have been looking for a solution for a long time now but unable to find one :( There are some questions which are similar but none of those have been able to help. It will be helpful if any changes suggested are provided with the exact location where it needs to be changed. Needless to say I am a newbie.
Thanks
You need to mark the relevant variable that contains the html snippet in your template as safe
Obviously you should be sure, that the text comes from trusted users and is safe, because with the safe filter you are disabling a security feature (autoescaping) that Django applies per default.
If your ckeditor is part of a comment form and your mark the entered text as safe, anybody with access to the form could inject Javascipt and other (potentially nasty) stuff in your page.
The whole story is explained pretty well in the official docs: https://docs.djangoproject.com/en/dev/topics/templates/#automatic-html-escaping

Joomla Load Module in Featured Article

What I use:
- Joomla 2.5
- gantry framework
Need:
I must place in my homepage a slideshow module inside the mainbody as a featured article.
What I did:
Installed a slideshow module and placed temporary inside gantry's maintop-a position to see if it worked (it did), then moved in a non-previously-exsisting 'slideshow' position.
Created a new article, with this content: {loadposition slideshow} and set it to featured state.
Result:
the article was published correctly but the introtext char limit trimmed the actual module code to 100 chars making it useless.
What I already tried to fix the issue:
Modified my slideshow article from database adding the loadmodule code in the fulltext field (which was originally empty),
then modified components/com_content/view/featured/tmpl/default_item.php replacing echo $this->item->introtext; with an if to identify my slideshow article id then query the database to find the fulltext field and echo it. this thingy works but the loadmodule function isn't, so it's displayed as simple HTML. I deduce that introtext is treated differently than fulltext since what's inside the brackets is interpreted as code only when echoed as introtext, and I miss that layer.
Modified modules/mod_articles_category/helper.php to break the 100 introtext_limit, sadly finding that's not called for my featured articles (added dump($item, 'some name') which returns only the articles that are inside my news sidebar, even if all my featured articles including slideshow are categorized)
tried a million different combinations of the above (i.e.:{loadmodule slideshow}{module [myslideshow_article_id]} <- a module loader plugin i tried, ...) which are too long to put here.
Searched the whole project folder for files containing 'introtext' inside their code, finding alot, but nothing that actually trims it (except helper.php of course)
Searched the Joomla API
Googled for everything that came into my mind finding no working solutions.
Came Here :)
Thanks
If you want to show a module inside an artice, you can use an component to show them there.
In my experience, this works on normal and featured articles, so this might work for you:
http://www.nonumber.nl/extensions/modulesanywhere
I hope this was helpfull, since this is my first answer here.
Kind Regards,
McBurgerKong

MVC - Strip unwanted text from rss feed

Ive got the following code in my RSS consumer (Vandelay Industries RemoteRSS) in my Orchard CMS implementation:
#using System.Xml.Linq
#{
var feed = Model.Feed as XElement;
}
<ul>
#foreach(var item in feed
.Element("channel")
.Elements("item")
.Take((int)Model.ItemsToDisplay))
{
<li>#T(item.Element("description").Value)</li>
}
</ul>
The rss feed Im using is from Pinterest, and this bundles the image, link, and a short description all inside the 'description' elements of the feed.
<description><a href="/pin/215609900882251703/"><img src="http://media-cache-ec2.pinterest.com/upload/88664686384961121_UIyVRN8A_b.jpg"></a>How to install Orchard CMS on IIS Server</description>
My issue is that I don't want the text bits, and I also need to prefix the 'href=' links with 'http://www.pinterest.com'.
I've managed to edit the original code with my newbie skills to the above,, which essentially displays the images as links which are only relative and thus pointing locally to my server. These images are also then followed by the short description.
So to summarise, I need a way to prefix all links with 'http://pinterest.com' and then to remove the fee text after the image/links.
Any pointers will be greatly appreciated, Thanks.
You should probably parse the description, with something like http://htmlagilitypack.codeplex.com/, and then tweak it to add the prefix. Or you can learn regular expression and do without a library. Could be a little trickier and error-prone however.

Django: DRY Internal links in TextFields

I have a site with a bunch of 'Projects' which often refer to each other in their descriptions (stored in a TextField).
Rather than hard-coding the links between projects in their descriptions, I'd like to keep things DRY by referring to them using some sort of token, for example, in the description field:
Blabla text describing this project, this project was inspired by
{{ project "ProjectB"}} and lead to the development of {{ project "ProjectC" }}.
Which is then processed and turned in to:
Blabla text describing this project, this project was inspired by
ProjectB and lead to the development
of ProjectC.
To be clear: the description is free text which can contain none to many references to other items as hyperlinks at various points in the text. In a CMS this effect is usually achieved through some way to link to items by node/object ID - so that if the link changes, the reference can still be followed.
I've considered:
Evaluating the text field as a Template and using the 'url' templatetag in descriptions. Seems like the easiest solution but that templatetag isn't particularly friendly for content editors and evaluating each description through the entire Template renderer seems a bit cumbersome.
Implementing a templatetag which just re-implements a basic faux-templating system to just parse out a nice simple tag just for this purpose.
Extending the TextField to pre-process the description before it's saved to the database.
Has anyone done anything similar? What would you suggest?
I just answered a similar question on SO, and it seems like it might solve your problem as well (if by chance you're still looking for an answer three years later).
I wrote a template filter to parse the custom internal link format in the Textfield before display. I'm using Markdown to parse my textfields, so I made the links return in Markdown format, but they could easily be written as HTML instead.
Check out my answer here.
Update: I posted a revised version on djangosnippets.org that resolves internal links inside a markdown-formatted link, as well as on their own.
if I got your problem, you should use a custom template processor to pass a dictionary to your templates:
in settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"myapp.myprocessor.foo",
)
in myapp/myprocessor.py:
from django import template
def foo(request):
ProjectA = get_Project_from_database
t = template.Template(ProjectA.html)
c = template.Context({'name': ProjectA.name})
rendered_ProjectA = t.render(c)
return { 'rendered_ProjectA': rendered_ProjectA }
or if you don't wanna use Django template system you can use regular expressions (import re)