Sitefinity 4.4 - Dynamically change page title and description at runtime - sitefinity

Does anyone know how to dynamically change the page title in Sitefinity from a regular user control?
Our scenario is simple. We have a real estate website with a search feature. On the search results page we have a control showing the search results, but we need to be able to change the Page title, description and keywords based on the search performed.
We posted on Telerik, but they gave vague answers and pointed us to incorrect objects or objects that didn't actually work.
?
Regards,
Jacques

The way I've usually done this in the past is by using an external widget template.
By mapping your widget template to an external file, you can use a full User Control (.ascx file) which means you can also run code behind.
From there it's just a matter of running something like
Page.Title = "whatever";
For more info on using an external template for Sitefinity Widgets, check out this post: http://www.sitefinity.com/blogs/joshmorales/posts/11-05-10/mapping_external_templates_for_sitefinity_4_widgets.aspx
Hope this is helpful!

Related

Get blog post custom field in template head - Sitefinity

I need to set several meta tag values in my page head to values set in blog post custom fields.
How do I access the blog item viewmodel from the head?
I've created a separate MVC view snippet for my custom head and referenced it in my template's layout, that much works.
Tried
I grab some of the same custom field values inside my blog template via references like Model.Item.Fields.MyFieldName.Fields.Title.
Adding this same line to the head template throws a
System.Web.HttpCompileException with little useful information attached. I somewhat expected this, as I suspect that viewmodel for the blog post only exists in the context of the blog widget.
Ends up that I need to rebuild after every change to the head cshtml file or I get this error. Seeing as this is about a four-minute process with Sitefinity (15 seconds to build, 3:45 to do whatever Sitefinity does for about four minutes), this is a gruelingly horrid thing to have to do.
However the Model is null at this level.
Also tried
Per the ever-helpful and highly knowledgeable #Veselin Vasilev, I looked into passing the data up via MetaDataFields. I didn't see these options in my admin section for the widget. To clarify, I'm using the built-in "Blog posts" widget with a customized view file.
But if it's possible to do this, it gives me hope that there's a way to pass more data up, even if it's going to take some work.
EDIT: Sitefinity v.10.2 and above:
There is an easier way to achieve what you are trying - in Page edit mode, in the Blog Posts widget click Edit and then Advanced. Then you should see a MetaDataFields button. Click it and you should see several meta data related fields.
In the MetaTitle field put the name of your custom field and save.
Also, from the docs:
If you leave MetaTitle field empty, Sitefinity CMS adds takes its value from the Title field of the static content item or from the identifier field of a dynamic content item. Otherwise, the tag is populated with the contents of the field that you have entered in MetaTitle field.
More details here:
https://docs.sitefinity.com/configure-meta-title-and-meta-description-on-widget-level
Sitefinity 10.1 and below:
Check this article
Basically, in your view you get a reference to the Page object and then update its Header with the meta data you need.

Extend Page Property with custom controls in Sharepoint

Sharepoint is quite limited when it comes to multi-Lookups because it saves that information in strings. So I changed the Page-Property
"Elements (MultiLookup-> elementIds" on the propertyPage
to an inserted List "PageElements":
"
(SingleLookup)pageId , (singleLookup) elementId"
Because this is quite hard to maintain for my content admins I want that they can enter that information in the page properties like before instead of adding lines into "PageElements"
Therefore I want to add a control that handles that.
I do not need a solution for the task how to achieve that specific function, but a general hint how to add any custom control into a Page property.
I starting point link would be very nice. I just doen't seem to find the right words to feed google with my topic.
Solved this by using a custom field type with that logic. Basicly Described here: http://avinashkt.blogspot.de/2011/07/creating-custom-field-in-sharepoint.html

Sitefinity 5.X: Override how page title is generated

http://www.sitefinity.com/devnet/forums/sitefinity/developing-with-sitefinity/override-how-page-title-is-generated.aspx#2050837
I would like to override how the page titles for all pages on a site are generated. The client wants the title to be similar to the site breadcrumb where it is a concatenated list of ancestral page names plus the current page.
I figure that this could be generated when a page is saved but I would have to alter the page title of the current page and all child pages. If I did it this way then if they changed their mind later then I would have to regenerate all of the page names.
Alternatively if I could just override how the page titles are put on the page then I could go get the ancestors and generate the title when the page is viewed by a user.
I lean toward the second but I don't know how to do either. Any ideas?
I am working on 5.X.
just cross posting the answer you got on the forums in case anyone is looking here.
The answer from Liam was to refer to this KB article: http://www.sitefinity.com/devnet/kb/sitefinity-4-x/globally-overwriting-properties-for-frontend-pages.aspx
which allows you to use global.asax to override the properties globally. pretty slick, I wasn't aware of it!
My suggestion was if you need to do it at the template level to use the SiteMapBase.GetActualCurrentNode() method to do it manually.
hope you got it all worked out!

Programmatically adding metatags to Masterpages in Web Forms and MVC

Has anyone got any ideas on where we should be adding our SEO metadata in a Web Forms project? Why I ask is that currently I have two main Masterpages, one is the home page and the other one is every other page, they both have the same metadata that’s just a generic description and set of key words about my site. The problem with that is search engines are only picking up my home page and my own search engine displays the same title and description for all results.
The other problem is the site is predominantly dynamic so if you type in a search for beach which is a major categories on the site you get 10000 results that all go to different information but all look like a link to the same page to the user.
edit
It's live here www.themorningtonpeninsula.com
Don't know why this post was moved here either, I put it up on stackoverflow.com. I didn't know about this site but I'm glad I do now!
It is in its essence a programming question and the answer is to use dynamic meta tags to your pages and your the master pages. If you do a search on this most of what comes up is "How to add meta tags to your masterpages" that's easy but not a good idea!
Put this in the page_load of you page then populate the hard coded bits from the database.
Page.Header.Title = "Some new dynamically created page Title!";
Page.Header.Description = "Some dynamically created description";
Page.Header.Keywords = "stuff, more stuff, even more stuff";
HtmlMeta myMetaTag = new HtmlMeta();
myMetaTag.Name = "robots";
myMetaTag.Content = "noindex";
Page.Header.Controls.Add(myMetaTag);
Does the trick.
Cheers,
Mike.
Not sure why this got migrated here since it's really a programming question. To answer the SEO aspect: yes, all pages should have unique titles that describe the page, and usually a relevant meta description.
Note, search engines are picking up all your pages, as a search for site:www.themorningtonpeninsula.com will show you. But since they all have the same title they are probably not appearing in normal searches.
For the technical side, you can definitely set the page title when using master pages in ASP. I think you can set the title when you create a new page, but if not the first line of each page should have the title attribute like in this code from one of my projects. Here the title would be "Help pages":
<%# Page Language="VB" MasterPageFile="~/MasterPage.master" CodeFile="Help.aspx.vb" Inherits="Help" title="Help pages" %>
I'm not 100% sure about the meta description but it should be possible to set that in the VB/C# code behind the page. If you can't get it working I'd recommend asking a more specific programming question on Stack Overflow.

Question regarding how a public SharePoint site is made

I had a look at http://www.westernaustralia.com/au/Pages/Welcome_to_Western_Australia.aspx and I know it's a SharePoint site and I am wondering how it could have been made.
I am mostly interrested in the center column (What's On). Is it an announcement list with thumbnails and Find out more links are pointing to wiki pages? Could it be a custom web part or is it possible to do this sort of thing with SharePoint 2010 out of the box?
Thanks in advance.
You can do this easily with a "What's New" web part. Customize your library view setting and set your webpart to use that view. Add a simple content editor at the bottom of this web part and add those other links like View All etc...
Remember that you can create your own list and make sure to index it so that it can rollback into the What's New webpart.
Looking at the emitted HTML it looks like a custom user control in the page layout to me (hell I could be wrong)
That said though it is possible to do this OOTB and I could build that functionality using the Content Query Web Part and some custom XSL