Updating page content programmatically

I’m just getting started with Litium and trying to do some basic tasks to get my head around the system, but I’m having a hard time understanding the documentation.

Basically, I am trying to create a “Regular page” (Article) and populate the fields: “Introduction” and Text1 with text.

I had no problem creating the page or listing the fields/properties but I can’t for the life of me figure out how to set/update the values. Hera are my play code:

        string outout = "PageTypes:\n";
    foreach(PageType type in pageTypes)
    {
        outout += type.Name +"\n";

        if(type.Name == "Article")
        {
            
            Page currentPage = pcc.CreatePage(type, type.DefaultTemplate, "TestCreate", true, securityToken);

            //I read someware that i should do it using, PageCarrier but how?
            var pc = currentPage.GetAsCarrier(false, true, true);
            currentPage.UpdateFromCarrier(pc,securityToken);


            var props = currentPage.Content;

            outout = "Property:\n";
            // Or can i update the fields here  when loopign over the props?
            foreach (Property prop in props)
            {

                outout += prop.Name + "\n";

            }
        }
    }

Litium version: 6.2

You need to cast the Property into the typed property, example StringShortProperty and there you have get/set methods for the values. All the different property types exists in the Litium.Foundation.Modules.CMS.Content namespace.

Example

foreach (Property prop in props)
{
    outout += prop.Name + "\n";
    if (prop is StringShortProperty stringShortProperty)
    {
        output += stringShortProperty.GetValue() + "\n";
        stringShortProperty.SetValue("my new value", SecurityToken.CurrentSecurityToken);
        output += stringShortProperty.GetValue() + "\n";
    }
}

Fantastic, thanks! anything I need to know about PageCarrier? I remember reading that that was the “New way” of updating. Can you tell me something about the logic there? What are a Carrier and how is it used in regards to updating?

Use UpdateFromCarrier when you need to update multiple values of a page at the same time.

The carrier is used to contain the data of a page object, same as OrderCarrier for an order for example.

So, I use the Carrier the same way? Like: stringShortProperty.SetValue(“New Value”).
But then i need to pass it via UpdateFormCarrier(carrier) to update the values? or are the update logic different?

And without a Carrier the database is updated on every SetEvent call?

Search for PageCarrier in \src\Litium.Accelerator\Deployments\CmsStructurePackage.cs to see usage examples.

And yes on db being called on every Set() call otherwise, this pattern is no longer used in the new API which is currently avaliable for PIM, Media and Customers.