Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Reusing content from one web page in another

$
0
0

Hi David,

here is how you can use Pauli's code way without using Visual Studio:

  1. On the Functions perspective, C# Functions execute the "Add Inline C# Function" command
  2. In the dialog name it GetPageContent - set namespace to MyTools. Click OK
  3. Paste in the C# code shown below in the "Source" tab (delete what is there already)
  4. On the Input Parameters tab, create to items:
    1. "Page" of type DataReference<C1 Page>
    2. "Placeholder" of type string
  5. Save.
  6. Tnsert your function on a page or call it from an XSLT and you should see your content show up :)

You can change both namespace and function name - just remember to do so in both the source code and the Settings tab - they need to match up.

using System;using System.Linq;using Composite.Core.Xml;using Composite.Data;using Composite.Data.Types;namespace MyTools
{publicstaticclass InlineMethodFunction
	{publicstatic XhtmlDocument GetPageContent(DataReference<IPage> Page, string Placeholder)
		{using (DataConnection dc = new DataConnection())
			{
				Guid pageId = (Guid)Page.KeyValue;var placeholder = dc.Get<IPagePlaceholderContent>().SingleOrDefault( f=> f.PageId == pageId && f.PlaceHolderId == Placeholder );return (placeholder == null ? null : XhtmlDocument.Parse( placeholder.Content ));
			}
		}
	}
}


Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>