Dato Config RB

I am trying to loop through a modular block on a page. I am trying to limit the data that goes into the collection but dato is giving me the kitchen sink. How can we limit the data??

dato.config.rb

inside a ā€œ_postsā€ directoryā€¦

directory ā€œ_feature-pagesā€ do

ā€¦iterate over the ā€œBlog postā€ recordsā€¦

dato.feature_pages.each do |feature|

# ...and create a markdown file for each article!
create_post "#{feature.slug}.md" do
  frontmatter :yaml,
    title: feature.title,
	permalink: feature.permalink,
	layout: "feature-page",
	pl: "..#{feature.permalink}",
	h2: feature.h2,
	summary: feature.content,
	order: feature.order,
	background: feature.background,
	image: feature.image.url(w: 800, fm: :png),
	thumb: feature.thumb.url(w: 200, fm: :png),
	topimage: feature.top_image,
	seotitle: feature.seo.title,
	seodesc: feature.seo.description,

	related: feature.related_features,
	item: feature.feature_items do |items|
		items.feature_item_title
		items.feature_item_slug
	end


  content(feature.content)
end

end
end

I need to get the data out like this

hello @derrick, Iā€™m pasting the answer publicly here as well as it might benefit someone else.

In your case the SEO field is optional, and so it might be empty. You need to check for that in your script to prevent hitting a null object.

In particular you can do something like this:

        seotitle: feature.seo ? feature.seo.title : '',
        seodesc: feature.seo ? feature.seo.description : '',

Or alternatively you can make the SEO attribute required and leave your script as it is. That depends on how you plan to do things.

didnt work

$ bundle exec dato dump
DEPRECATION WARNING: Ruby 2.5+ (required by Rails 6) provides Hash#compact and Hash#compact! natively, so requiring active_support/core_ext/hash/compact is no longer necessary. Requiring it will raise LoadError in Rails 6.1. (called from load at C:/Ruby26-x64/bin/dato:23)
Fetching content from DatoCMSā€¦ Traceback (most recent call last):
25: from C:/Ruby26-x64/bin/dato:23:in <main>' 24: from C:/Ruby26-x64/bin/dato:23:inloadā€™
23: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/exe/dato:10:in <top (required)>' 22: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/base.rb:466:instartā€™
21: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in dispatch' 20: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:ininvoke_commandā€™
19: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in run' 18: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/cli.rb:47:indumpā€™
17: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/runner.rb:25:in run' 16: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/runner.rb:25:innewā€™
15: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/root.rb:25:in initialize' 14: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/root.rb:25:inevalā€™
13: from (eval):4:in initialize' 12: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/root.rb:33:indirectoryā€™
11: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/root.rb:33:in new' 10: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/directory.rb:22:ininitializeā€™
9: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/directory.rb:22:in instance_eval' 8: from (eval):7:inblock in initializeā€™
7: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/local/items_repo.rb:194:in each' 6: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/local/items_repo.rb:194:ineachā€™
5: from (eval):10:in block (2 levels) in initialize' 4: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/create_post.rb:27:increate_postā€™
3: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/create_post.rb:27:in new' 2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/create_post.rb:11:ininitializeā€™
1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/dato-0.7.5/lib/dato/dump/dsl/create_post.rb:11:in instance_eval' (eval):23:inblock (3 levels) in initializeā€™: undefined method `titleā€™ for nil:NilClass (NoMethodError)

once I copied and pasted from the email it worked. thanks so much

		seotitle: feature.seo ? feature.seo.title : '',
		seodesc: feature.seo ? feature.seo.description : '',

this is what fixed it

1 Like