How to customize the HTML code of Content Query Web Part - sharepoint

I want to custom the output HTML code of CQWP and I do not want to see <table class="s4-wpTopTable">...</table>. But even I try to edit ContentQueryMain.xsl file by the help of this article:Customizing the HTML code of a Content Query Web Part, the table is still there.I can't even find any code generated the table which class is "s4-wpTopTable".
So ,I need some talent guy to tell me how to stop the CQWP to generate TABLE.
I have tried to set the Content Query Webpart's SuppressWebPartChrome to "True",but the table is still there, such a big problem.

I faced problems like you had and I decided to develop a web part that makes it easy to customize the look & feel of a portal. You can find detailed information about it here: Item Lister Web Part

If you want to customize the output HTML of CQWP,you should:
Insure your CQWP is NOT in the webpartzone, because the webpartzone will make the the SuppressWebPartChrome does not work for your webpart.
Insert your webpart to the page with the help of SPD,and then in the code view,you can change the SuppressWebPartChrome of CQWP to True(Defualt is False).
Look at the source code of your page,the <table class="s4-wpTopTable">...</table> is not there now, cool!
Anyother addtionnal code generated by sharepoint of the CQWP,you can custom it in your ContentQueryMain.xsl file, so you should learn the language--XSTL .Don't be afraid of it,it is so easy for you to learn in one hour.

Related

How to make advanced CMS-like blog system from scratch?

When you create a news or blog tab with CMS it's really easy to make a feed of posts with content preview. Also when you follow a link to a particular post you can notice that it consists of a different html tags and css styling and not just plain text. It just uses rich text editor. So just getting text from db is not enough.
My question is how to achieve the same result when making a website from scratch. It doesn't matter what language is used for back-end. I'm just interested in the idea how to do it. But if you could provide a code examples (with any language) it would be greatly appreciated
Ok I've figured it out. Posting the answer for somebody who will have the similar question in the future.
The idea is that you need to put a text with html tags into your database and then to retrieve it you need to put it in your desired div in unescaped state. The thing is that almost all view (template) engines escape html tags by default. To do that you have to use some built in functions specific to that view engine.
To put the article with html tags in db you can just write raw html into input field or you can somehow add richtext editor to input field. Richtext editor will generate html for you.
I've researched it and found out that that's exactly how cms work.
So there you have it. If you want to add something feel free to do it

Kentico 10 - Web Part content change via database

i was trying to understand in the Kentico's database model how can i change the web parts content using a database script.
So, basically i have a website based on Kentico with several articles, and internal hyperlinks in its content. But the problem is that the format of those hyperlinks are actually invalid. And i was looking for a way to build a script and do a bulk-update in order to replace some characters and update those hyperlinks to the valid format.
Any idea how can i build the query to get the content of all web parts used in all published pages.
Thank you
It depends on your web parts and how the content is rendered. There are different ways that web parts render their content:
The web part layout is used for markup
The ASCX file for the web part is used for markup
The web part makes use of a repeater that uses a Transformation to render the markup- The markup is generated in code behind
The last one can be tricky to change depending on the web part and whether you have access to all the code behind, but the others you can change either in code in your solution or within the Administration area itself.
Doing this in SQL would probably require a combination of T-SQL XML support and regular expressions to find what you're looking for. you effectively need to look in the CMS_WebPart and CMS_WebPartLayout tables to find what you're looking for.
However, reading your query, I'm not 100% sure you're talking about web parts, (my apologies if you are) as you talk about links in the article content itself. If these are set using the Editable text web part, then you need to look in the CMS_Document table at the DocumentContent field to find the links to replace. But you then need to look at how to correctly format those links going forward so that you do not need to repeat this process later.
Note:
You need to be really careful when doing this in SQL to make sure that you don't create invalid XML. Things go bad when you do that.
This won't flush your cache, so you'll need to clear your cache manually afterwards.
If you're using out-of-the-box web parts, you should really make a copy of them and use the copy if you're going to modify, this way, you're less likely to have pain in future upgrades.
Typically "content" is not set in a webpart. Webparts are configured to retrieve content from page types. There is an exception to this with specific webparts like Editable Text, Static Text, Static HTML, etc.
The configuration of a webpart is stored at the template level in the cms_pagetemplate table. The configuration for ALL webparts on that page template are stored in the PageTemplateWebParts field. So you'd have to parse through the XML and get the proper webpart and then perform an update on that field. You maybe able to do a regex to find that content and replace it as well.
Not ideal to do this via SQL simply because of version history and it can cause a lot of problems later on. I'd suggest finding out which API calls you can make to perform these updates and write a small program for it.

XSLT Web Part to display HTML

Please excuse if there is a better way to do this, I'm not too familiar with SharePoint web parts, I'm only just now getting into creating them.
What I want to do is have a web part that I can drop into a page, give it a parameter, and then the web part does it's API calls with said parameter, does some XSL transformation, and spits out the HTML that I want to display on the page. In my mind it seems like a simple little web part to write, I just want to make sure this is the best way to go about it and not be duplicating something that could already be existing.
I've gone through this creating a basic web part walkthrough, and I figure I can use the web part property to get the parameter from the user. How would I get it to output HTML though? I changed the "Hello, world!" text to output some HTML and it seemed to have gotten stripped out?
Thanks a ton, and sorry if anything seems noob-ish!
From what I see, there are two main parts to what you want to do.
Get your parameter into your query
Format the results with some HTML
Reuse it later
There are a lot of ways to do this, but I'm going to outline what I believe to be the fastest and most simple.
Getting your parameter into your query
In SharePoint 2010, SharePoint designer has some great options for this.
So step 1 is to open the webpage in SharePoint Designer.
Click the Insert tab and click the Data View dropdown and select the list you want to get data from.
Now click on the Options tab and click on Parameters
The dialog shows you some of the options for pulling info into your query.
A query string parameter is easy to use. And the server variables are also really handy.
For our example, we'll pick query string and set the default value to 1 (which will be the ID of an item we want to be retrieved). Since we've set this as the default, even if the query string is blank we'll still get our default in our parameter.
Then click on Filter.
We set our Field Criteria to use the parameter we just made.
Now you can save the page in SharePoint Designer and test your results. Pretty fast.
Format the results with some HTML
In SharePoint, XSLT is the best way to put your own HTML around some data you've retrieved from SharePoint.
Also, for getting a parameter into your query, we can add that with a parameter binding:
If you're new to XSL, here's the best xsl tool:
http://spexp-blog-files.s3.amazonaws.com/blog/files/spe-magic-data-view-builder.xsl
To use the magic dataview builder, save this file to documetn library in your farm.
If you’d like to centralize your XSL template for greater reuse (highly recommended), you can put the individual XSL files into a central location for storage. In a WSS or SharePoint Foundation environment, I’d recommend using a Document Library in the root site of your Site Collection. In a MOSS or SharePoint Server 2010 environment, I’d recommend placing the XSL files in the /Style Library/XSL Style Sheets location, as this is where SharePoint stores its XSL by default.
Then paste the url to the file into the XSL Link to replace main.xsl and change Default to FALSE. This property is located near the end of the <XmlDefinition> tag as you view the webpart in Designer.
... <XslLink Default="TRUE">main.xsl</XslLink><Toolbar Type="Standard"/></View></XmlDefinition>
From there, you can save the page and the XSL wizard from magic data view builder will walk you through creating your own xsl to output your html.
Reusing Your Webpart
To reuse it, click save "To Site Gallery" while your cursor is on the wepart in SharePoint Designer. This will save the webpart into the gallery under the "Custom" group. From there, you an insert your webpart into other pages just like the out of the box webparts.
I think we need more information about what you are trying to get the web part to do. If you use a SharePoint Data View web part, you can point it at a data source, write some XSL to transform the data to render the way you want it will output the HTML to the page. For example, let's say I have a SharePoint list of training classes. I could create a data view web part that takes a query string or other input parameter as its filter, and filter the list of classes to show me just the one that matches the ID of my query string or input param. Then I could format my XSL to output details about the class rendered in whatever fancy HTML I want.
Does that help?
"I changed the "Hello, world!" text to output some HTML and it seemed
to have gotten stripped out?"
Please be aware that in your sample, it uses a LiteralControl() which by default HTML Escapes any text. So if you need HTML outputed via the LiteralControl.Text element, you will need to set the Mode to "Passthrough".
protected override void CreateChildControls()
{
base.CreateChildControls();
LiteralControl message = new LiteralControl();
// !! add this !!
message.Mode = LiteralMode.PassThrough;
message.Text = DisplayMessage; // <-- containing HTML
Controls.Add(message);
}

Is there a ootb sharepoint list control?

I need a control which simply outputs a list of items. Much like the summary link control but without the links. I thought about using the summary link control and use xsl to style the list, but the link field is required. So this is no good.
Is there anything?
Have you checked out the Content Query Web Part or the Content Editor Web Part?

Sharepoint Branding

I'm just tasked by my boss to create a Sharepoint solution for the scenerio below.
(I'm a total newbie to Sharepoint. So please forgive me if i use the terminology wrong)
The portal should open in a custom look than the default Sharepoint design and it should have links to the products. Every product page should have different look and feel but have same types of content. For example every product should have Published Materials list but with different set of content.
So, an example of the desired map is like this:
/Home
-Latest News
-Core Team List
-Products
-Product 1
-Product 2
-Product 3
I found Sharepoint a whole new and strange world. I thought i'm good at learning, until i met Sharepoint. Everything seems very detailed and i'm living difficulties in finding useful information quickly. Because i have no Sharepoint background and i don't event know what i'm lookin' for.
Could you please help me by telling me how can i accomplish this or even just telling me the name of "thing" that i'm trying to accomplish.
Thank you in advance.
PS. Oh, by the way, I learned the word Branding in my search for the holy grail. I don't even know that the word fits or not...
I did try the method you post on other page (Restaurant review site in SharePoint) but unfortunately i couldn't succeed. I stucked at choosing what type of content type in the "Create Content Type" page at first and then tried some parent types but i couldn't get it show up in Sharepoint Designer 2007's New Sharepoint Content "Publishing Page" dialog.
So i tried something else.
At my homepage created a new Document Library of type "Web Part Page" called "Products". It created me a some sort of list whose all items are web pages. At this point i felt that i'm near to accomplish something at last.
Here are some questions i've collected: :)
I add two Announcements web part to different "Products" pages. When I add a new announcement to the list from one product page, it shows up in the other one too! How can I make their content only visible in page that the content created on?
*[Theming is a recurring theme in my posts]* Is it possible to change the view of each Product page at this setup so they have different design and color?
Thanks.
Check out the links I posted in the answer to this question for some links to SharePoint 101 tutorials online:
Restaurant review site in SharePoint
Given you're looking for 'branding' that will mean a custom Master Page. A Master Page is what will determine the overall layout of your SharePoint Web Application's pages. After creating a standard SharePoint application, connect with SharePoint Designer and play with that Master Page for a while until you get the hang of it.
In modifying or creating custom Master Pages, it is important to take note of all the controls (special ASP.NET server-side tags) in particular Content Place Holders; if you create your own Master Page and these are missing you're in a world of uninformative-error-message hurt.
You're going to want to create Lists ( http://office.microsoft.com/en-us/sharepointtechnology/HA011199881033.aspx ) to represent 'News' and 'Products'... for Products you may even want to create a Content Type.
Once you create 'News' and 'Products' lists, to see those lists of Products you'll want to make views and use List View Web Parts ( http://office.microsoft.com/en-us/help/HA100240521033.aspx ) to include those views in Pages... but at the subject of Web Parts this is probably getting a bit overwhelming so I'll stop here. Comment me if you'd like more.
Addendum
"Is is possible to show only categories of a document library in home page and documents of the selected category in another page?"
-> Yes, and there are several ways. I'd suggest you look into either defining a View for that list which filters based on the category field, then add List View Web Parts to your home page, or writing custom XSLT for the Content Query Web Part, and then add it to your home page. Writing the XSLT for he Content Query web part is a little more difficult, but using the List View has it's short comings in being not-as-configurable, much like this guy is finding out: No-code solution for calendar view of SharePoint news items
"But how can i change a list item to show its details as a whole new page with its own web parts and theme?"
-> Here's the kicker; in SharePoint, each Site you create has a special list for Pages, and each Page actually belongs to a Content Type.
So you can take any content type and turn it into a page; all you have to do is create a Page Layout for it, and add that Content Type to the list.
(So, an example. This is purely speculative; I'm not saying do this specifically, and you probably can't do it exactly as I describe it as I'm oversimplifying a little)
You create a Content Type 'Product', but you also decide 'Category' should be a Content Type too. So you create a content type for 'Catagory', and you give it a lookup column, which refers to items in the 'Product' List. You specify that the lookup can contain multiple items.
Now you want a Page where people can see a category, and all the Products which belong to it. You create a 'Page Layout' (an aspx file) for the 'Catagory' Content Type. In the Page Layout aspx file you can include web controls which render the Catagory's fields, such as 'title' and 'description' and you can probably even add one to render the 'Products' lookup field. (maybe you'll have to code it yourself)
I hope I haven't lost you.
Now that you've created a Page Layout for 'Catagory' you can add 'Catagory' to the Pages list/library and then create pages which represent Catagories, and when people edit those pages, they will also edit the Catagory.
More Addendum
If "Announcements" is a list, the web part you added was a list view web part, and so it just shows the contents of the list (which is independent of the product pages)
You'll want o specify filters of your view. I dunno if you can specify unique filters on the web part... but you can try :)
You might want to consider looking into The Content Query Web Part.
I don't fully understand your second question, but I get the feeling the answer is yes... what do you mean by "view"? You gotta be careful with the lingo; do you mean the Page Layout? or the List View Web Part? or the List View? or the Master Page? ...
you HAVE to check out Heather Solomon. She is the shiznat when it comes to sharepoint branding.
A good start would be using Sharepoint Designer.
Use SharePoint Designer to do your CSS work, particularly in discovering the CSS rules in play. DO NOT publish the finished work from SD; if you do, future Windows Updates may wipe out your files. Instead, deploy your customizations as a Feature. In MOSS 2007, you can add a single custom CSS file using Central Admin - this will then be applied AFTER core.CSS at runtime, To the best of my knowledge, this is the only practical way of doing this.
You need to indicate whether you are using WSS or MOSS. With WSS, you can use themes.

Resources