Learn how Scrivito CMS can help you deliver amazing digital experiences
See Scrivito CMS in action

SDK Cheat Sheet

SDK Cheat Sheet

Variables: o CMS object, w widget, x CMS object or widget, a array, i image object

Working copies

# Set the current working copy Scrivito::Workspace.use("News update")
# List all working copies Scrivito::Workspace.all
# Create a working copy Scrivito::Workspace.create(title: "New Blogpost")
# Find and delete a working copy Scrivito::Workspace.find("3ff7b2a591c47dd1").destroy Scrivito::Workspace.find_by_title("News update").destroy

Pages & resources

# Create a blogpost o = BlogPostPage.create(title: "Hello world!")
# Find a page or pages o = Obj.find("f3d1e8a4c2342b83") a = Obj.find(["id1", "id2"]) o = Obj.find_by_permalink("blog") o = Obj.find_by_path("/blog/2016-02-17")
# List custom attribute names of a page o.attribute_definitions.map(&:name)
# Upload an image i = Image.create(blob: File.new("cat.jpg"))

Updating attributes

x.update(title: "New post") o.update(tags: o.tags + ["tech", "conference"]) x.update(color_enum: "blue") x.update(meta_robots_multienum: ["noindex", "nofollow"]) x.update(head_image_reference: Image.all.first) x.update(gallery_referencelist: Image.all.take(3)) x.update(home_link: Scrivito::Link.new(obj: Homepage.all.first)) x.update(links: x.links << Scrivito::Link.new(url: "http://example.org")) x.update(release_date: 1.day.ago) x.update(thumbnail_binary: File.new("kitten.jpeg")) x.update(html_content: "<p>Lorem ipsum</p>")
# Prepend widgets to a widget list x.update( main_content: [ HeadlineWidget.new(headline: "Hello"), TextWidget.new(content: "World") ] + x.main_content )
# Populate a widget list with nested widgets x.update(main_content: [ TwoColumnWidget.new( column_1: [HeadlineWidget.new(headline: "Hello world!")], column_2: [ImageWidget.new(image: Image.all.first)] ) ])

Searching objects

# Find all objects except various binary ones, e.g. for generating a sitemap a = Obj.all.and_not(:_obj_class, :equals, [Image, Download]).to_a
# Find blogposts that don't have a permalink a = BlogPostPage.where(:_permalink, :equals, nil).to_a a = Obj.where(:_obj_class, :equals, BlogPostPage).and(:_permalink, :equals, nil).to_a
# Find blogposts whose title contains 'brand' a = BlogPostPage.all.and(:title, :contains, "brand").to_a
# Find blogposts containing at least one GoogleMapsWidget a = BlogPostPage.where(:_obj_class, :equals, GoogleMapsWidget).to_a
# Find the most recently changed blogpost o = BlogPostPage.all.order(_last_changed: :desc).first
# Print ID, permalink, and title of all blogposts puts BlogPostPage.all.map{ |o| [o.id, o.permalink, o.title].join("\t") }.join("\n")
# Find all instances of a specific widget type Obj.where(:_obj_class, :equals, "ImageWidget").map { |obj| obj.widgets.select { |w| w.is_a?(ImageWidget) } }.flatten
# Find all objects linking to a specific image a = Obj.where(:*, :links_to, i).to_a
# Find all objects not linked to or referenced by other objects Obj.all.select { |obj| Obj.where("*", :links_to, obj).size == 0 }

Bulk operations

# Change all headline widgets of a page o.widgets.grep(HeadlineWidget).each do |w| w.update(headline: w.headline.titleize) end
# Replace all images contained in blogposts i = Image.create(blob: File.new("ad.jpg")) BlogPostPage.all.each do |o| o.widgets.grep(ImageWidget) do |w| w.update(image: i) end end


# Create a page type > rails g scrivito:page BlogPostPage
# Create a widget type including attributes > rails g scrivito:widget QuoteWidget quote:html author:string