I have been researching how to use the SPSite site = SPContext.Current.Site reference to pull the current site name, but I am unsure how to call this in a content editor web part. All I need is the site "Title" displayed, not the
URL, with the end goal being to use CSS formatting to create (nearly) on the fly banners for any new sites. I will be testing on SP 2007 but will ultimately be using on 2010, most likely linking web parts to .txt file to maintain formatting.
Thanks
|
|
||||
|
|
http://stackoverflow.com/questions/10835634/add-site-title-to-page-using-cewp to add the above javaScript:
or use
I dont know if im right I could be wrong but you could try the above and see if work which I think it should, sorry cant test it as I havent got acess to my sharepoint site! All you need to do is copy the code above and paste into the cewp. http://sharepointsolutions.blogspot.co.uk/2007/07/adding-javascript-to-content-editor-web.html http://www.ehow.com/how_10012230_use-javascript-sharepoint.html EDIT Ok, yes you are missing somthing ;) its not going to show anything as your not putting it into anything! all your doing is getting the title :) what you need to do to test it is encapsulate it with an alert to show you what it returns. For your case obviously you want it in a label to display within the cewp i presume. Please follow this guide first as its not great to add javascript straight into the cewp so you can do the following: http://techtrainingnotes.blogspot.co.uk/2012/02/sharepoint-how-to-add-javascript-to.html This way you can link to an external file that contains the javascript that you can edit properly in sharepoint designer or notepad++. Now for the code :) try this for now in the cewp, I know this works as iv just tested it out:
.......ok so now I know its working what i did was create a label and added it to the page ;) like so...
Now you need one last part as i stated at the top you need to add the Javascript tag like so:
Now this is working code that i know works as iv just tested it ;) hope you like it! just copy past the last section of code as its exactly what you want! Dont forget to follow the link to add the JS in a seperate file once you have tested on cewp. Otherwise youll be adding a version every time to the dom over and over again what really bad and would come into other problems :) Ok tested again and this works 100%, before it was loading before the page loads causing an error, to solve this i just made it wait till the page loads:
This should show up at the bottom half of the page but you can apply css to it using its class name dynamicSpan! Edit Only show part of the title To only show the second part of the title do the following:
If you want to show the first part of the title just change
to
I hope this helps :) |
|||||||||||
|

