luni, aprilie 02, 2007

Truly dynamic content SharePoint 2003

The purpose of this tutorial isn't immediately clear. What it does is that it allows you to add news articles to one list and mark them as separate content, so that you can have articles displayed on the home page, and you can have links to 'lone' articles that will only be displayed when you want them to.


If you are like me, you hate adding links to 'static' content on your Share Point 2003 site. We are going to create an announcement or news list that will display properly on your homepage, but it will also contain 'hidden' articles that are not displayed unless you provide their ID through the Querystring, and all list items are hidden except the one with that ID.


Here is a solution to THAT problem:


1. Create a news article list. Add a new column to the list, a checkbox (Y/N) and call it 'Hide'

2. Create a view that aproximates what you want.

3. Open that view in FrontPage.

4. Convert to XSLT.

5. IMPORTANT: Go into any of the cells that are in your list, and make a new table. Place ALL content into that table. Delete all webpart content that is not in that table.

6. Make it look pretty by arranging the content on the page the way you want it to look, changing fonts and all that too.

7. Go into Code view in Front Page.8. Search for "Title"

9. Look around the code for your table. The whole table will be enclosed in a tag.

10. Just before your table tag, add a div with class="ophogusshack{@Hide}" and id="article{@ID}"

11. Just after your closing table tag, add the closing div tag.

12. Step 10 and 11 enclosed each list item into a div, with a class of hidden (or not), and an id, so we can call them later.

13. Add the following css style: .ophogusshack1 { display: none; }

14. This class will hide all content that you don't want to display yet.

15. Do this: http://ophogus.blogspot.com/2006/06/filter-list-view-with-url-parameter.html

16. Add the following JavaScript to the bottom of the page in code view, but before the closing body tag:

<script><!--
if (browseris.mac && !browseris.ie5up)
{
var ms_maccssfpfixup = "/_layouts/1033/styles/owsmac.css";
document.write("<link rel='stylesheet' Type='text/css' href='" + ms_maccssfpfixup + "'>");
}

function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
//alert('Query Variable ' + variable + ' not found');
}
var IntRecordID = getQueryVariable("ID")
if (typeof(IntRecordID)!="undefined" && IntRecordID != "")
{
//alert('Displaying only article: ' + IntRecordID + ' and hiding all hidden and unhidden articles except ' + IntRecordID + '.');
promoBox();
document.getElementById('article' + IntRecordID).style.display = 'Block';
}
else
{
//alert ('Display Homepage articles, hiding all hidden articles (hide=1).');
//there is no js here, this should be expected default bahavior.
}

function getElementsByClass(searchClass,node,tag)
{
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';

var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");

for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}

function promoBox(){
// this searches for all elements with the class name required
// and creates an array

var el = getElementsByClass('barrysjshack0');

// this loops thru the array and sets the style you want
for (var i=0; i < el.length; i++){
el[i].style.display = "none";
}
}

//--></script>

That's all there is to it.

Despre mine

Timi-Ostravia, Republic of Czedvia, Bulgaria
I make web applications. The tools I use are many and far between. I have been maining to learn Ruby and Python, and Perl. These tools are all like Lego to me. They can all be make to build things and have their strengths and weakest.