How to create a testimonials page using Orchard CMS? - c#

I am very new to Orchard CMS and I am working on trying to create a testimonials page in my project.
I have created a content type that holds a body, textfield (TestimonialBy), and tags (for SEO purposes) called Testimonial. Now I need to create a page that will roll up all of my testimonials onto it.
I can create the content for the testimonial, and it is visible via navigating to the testimonial URL, however what I need to do now is create a testimonal page (localhost/testimonials) that will take ALL published testimonials and roll them up on one page so I could have:
Testimonial 1 content
-name of test giver
Testimonial 2 content
-name of test giver
etc
My question is, how do I do this?

You should create a content type like you've already done with the following parts:
Title Part (if you want it to have a title)
Autoroute Part (if you want it to have its own URL)
Body (for content)
Tags
Then enable the projector module.
Then create a query that lists your new content type.
Then create a new projection (or you can also use a projection widget) to show the content items returned by the query.
Updated for Orchard 1.4+

You should start by reading the documentation at Orchard Project, specifically the 'Extending Orchard' section which shows you how to create your own modules and content parts.
You could approach this in a few ways - one would be just edit the HTML of the page that has the testimonials and this is by far the quickest an easiest.
Another way might be to create a testimonial widget that lets you enter a name, quote, description etc. on the widget editor. You could then create a layer with the page's URL as part of the rule and just add widgets to the content zone. Because the widget would be driven by a content part, you could also add testimonials to your pages, blogs, custom content types etc.
Another way might be to write a controller for the admin interface that lets you do CRUD for testimonial records. You could then write a content part which lists these. You can then add this content part to a page, widget etc and with a bit of work add options so that you can control the testimonials that are shown on a per-content part basis.
Ultimately there are many ways to do this sort of thing in Orchard, it just depends on what you need and how much time/effort you want to put in to it.

Hmm. Sounds very close to a blog post. You might be able to create a testimonials blog and fill out the posts with the testimonial content.
Or u could add the containable part to the testimonial contentType and add the testimonials to the list.
Hope that helps
Dan

Related

How to avoid code duplication if multiple pages look almost the same?

I have a couple of pages for e.g. Product that look almost the same. I have Product/Add and Product/Modify/{id} pages where one is an empty form to add new Product and the second one comes already filled with data for a current product and can be updated with additional information. Because Razor Pages separates this into Add and Modify PageModels, I have a different cshtml view for each of them.
I tried to use ViewComponents to build reusable parts of these views, but they are only good if all you want to do is display data. Because ViewComponents don't support Binding all I have left is somehow send ajax requests and append the data to submit, which even sounds wrong and probably isn't the right approach.
Is there any other way of creating these pages without duplication?
You can create one page for create and edit by sending a new object of the Product model (with no data in id attribute) and a created object (with data in id attribute) in case of editing. And in the view you can do rendering based on the sent object (whether it is new or not).

Sitecore link to another page and also pass an object

I am working on a Sitecore project. I have an item in sitecore called Landing-page. Landing-page has an empty layout; with one placeholder. I have attached to this placeholder one controller rendering. From this controller rendering the whole of Landing-page is generated.
The main purpose of Landing page is to show all offers. Offers is of type Multilist. I have made Offers a multilist field on the Landing-page item.
In my single controller rendering method I am using:
var Sitecoreoffers = (Sitecore.Data.Fields.MultilistField)item.Fields["Offers"];
To access landing-page's Offer fields. In my action method that the controller rendering points to. I have constructed my own viewmodel that takes the Offers from the Sitecore item landing-page field and equals it to a C# List data type.
var Sitecoreoffers = (Sitecore.Data.Fields.MultilistField)item.Fields["Offers"];
What I want to do now is when the user clicks on an offer I get redirected to a offer detail page. In order to do this; I want to send the offer id to the Action Method; so that I can then access all of the offer's fields in the offer detail page. In C# you have the #html.ActionLink which is what I am currently implementing. Are there any advise about the best way to tackle this?
Given that in your implementation offers are "detail pages" themselves, the right way to link to them in your Sitecore site would be to generate a regular <a href> to those pages and let the browser perform a full page request to them.
The Sitecore API provides a class called LinkManager that has a static method called GetItemUrl which takes an object of type Sitecore.Data.Items.Item and returns a friendly URL to the item.
In your case, you would loop over the objects in your Sitecoreoffers collection and you would use LinkManager.GetItemUrl to get the friendly URL for each. You can then have a foreach loop in your razor file that generates the A tags for each Sitecore item in your Sitecoreoffers object.

Include hyperlinks in description of phone call entity

My code generates a phone call activity in each customer lead, then records the SMS conversation between that customer and the company. The description may contain an URL to an image that the customer finds relevant.
I can put the URL as text in the description property, but I would like to transform it to a hyperlink (something like an <a> tag of html.) That way I can click to open it directly instead of copy pasting the URL first.
How can I achieve this?
The description field on a phone call is just a plain old text field, so you can't add any formatting or hyperlinks there.
You could make a separate field, single line of text, with a type of URL. Then the URL you input should act as a typical hyperlink.
The data types are documented at Create and Edit Fields.
I believe you're asking about being able to have a large text area, within CRM, that is editable, but allows you to enter, or at least click on, hyperlinks.
I see two supported solutions, but both would take a lot of customization.
Create an HTML webresource that loads the text from the field, parses it, looking for hyper links, and then add's the correct <a> tagging in order for the links to be clickable.
Search for a client side wiki markup Text Editor widget of some sort (possibly something like http://goessner.net/articles/wiky/ ?), and then format the hyper links with the correct markup.
None of CRM data types support native full blown html rendering. If you try to use JavaScript to update the value and try to render it as html, it would trigger a save to the database as CRM would see the attribute value as modified.

Iterating over Sitecore Placeholder

I've been trying to iterate over a placeholder in sitecore. Essentially, there control that needs to be repeated by the page for a collection of elements (say a tab). I've only gotten the placeholder to render once. The following tabs don't have content inserted into them.
The code for something like what I'm trying to do is:
<asp:Repeater ID="rptTabs" runat="server">
<sc:Placeholder ID="plSocialSharing" runat="server" Key="Social"/>
<sc:Placeholder ID="plTab" runat="server" Key="content"/>
</asp:Repeater>
Should something like what I'm doing work? If it doesn't, do I need to user another sitecore control (something more dynamic?). Should I instead be using user controls I place there, or should I stick with the sitecore framework approach?
Since each of your tabs will contain the same rendering the I would not bother with placeholders. I think you will be adding more complexity than is required.
Assuming you are going to be using the jQuery UI Tab plugin then I would use the same technique you used in the previous question you asked, i.e. render out the content of the div tabs in the repeater, and you will need another repeater to create the ul list of the actual tabs.
Assuming you have a tree structure like:
- Social Sharing
-- Facebook
-- Twitter
-- Email
You could now Social Sharing use as the datasource of your Repeater and still allow the content of the tabs to be editable if you use Sitecore controls.
If you wanted something much more dynamic, like different rendering for each of the tabs, for example one with rich text, one with 2 column, one with table etc, then again there are a couple of ways of achieving this. One way would be to use standard <asp:PlaceHolder> in your repeater and add the rendering in this from your codebehind on ItemDataBound event.
Another option would be to add a bunch of different renderings into the placeholder in the page editor and set the datasource of each to content item. It will be difficult to use jQueryUI Tabs with this though since you would want markup like this in each control to make them self contained:
<div class="tab-title">Tab Title</div>
<div class="tab-content">Put whatever content you want in here</div>
As long as each rendering followed this structure then it would be easy to add several of these to the page and they would still be editable in the Page Editor, albeit listed one after another (not in tab format) in Editing mode. You would need to roll your own tab plugin, but it could be something as simple as:
Only in Preview or Normal mode
Get all .tab-title elements
Create a ul list and prepend to the tab container
Now call jQuery UI Tabs on the element
Hopefully given you some options at least, I can expand on any of these if it something you need but will have to get some code samples together.

Implementing paging in Sitecore content pages

I have a section on my website where I plan to add a lot of text-based content, and rather than display this all at once it would be nice if I could add paging on just these pages. If possible, I would like to put all of my content within one content item and have the paging work automatically, building a URL along the lines of http://example.org/articles/title?page=2 or similar.
I've stumbled across an article that mentions paging with Sitecore items and this seems rather close to what I require, although mine requires pagination on a single content item, rather than multiple items. Can someone help me adapt this article towards my needs (if it's on the right track of where I should be looking)?
Is it possible to do this with a Sitecore content item?
http://briancaos.wordpress.com/2010/09/10/create-a-google-style-paging-component-in-c/
I think you'd either want to create your own WebControl and define a custom Render() method that reads the query string to write out the correct information, or you could even do it all in a Sublayout (a user control ASCX file). I've done this before by adding in a custom tag in the Rich text editor via Sitecore (I think I used <hr class="page-break" />) then in my ASCX I'd look for that HTML tag and split the content into chunks from that. I think my solution also used jQuery for some of it but you could probably do it with C# too.
Edit:
You'd want to split the tasks up and have the "paged" content as well as a list of pages (like the article you referenced) so you can easily generate the page buttons. Both of these could be done in two separate repeaters.
You can split the text from a single field into the different pages using approach described here: Split html string to page. All you need to do after that - read the query string and display appropriate block.
If I understand you correctly you have an Item in Sitecore that has x number of text fields and you only want a subset of those displayed depending on input in the querystring ?
In it's simplest form you want a sublayout that handles that.
Basically I'd imagine you having fields called Text1, Text2, text3 etc.
This .ascx could then retrieve the data for fields the fields you'd want using the control and adding them.
Then you could use the code from the article to generate the paging links.
This should be simple enough, but I'd say it would be a better idea to have an item in sitecore and use it's children as the data you want viewed and paged.
It's nicer because if you start out with 5 "page" fields and suddenly want 10, your item will keep on growing, where children can be added without bloating the parent page. Plus the user could then order the children how he sees fit.
I hope this helps a bit.

Categories