If you are working on development/staging environment, you might want to preview the latest version of records instead of the published one. In this case, you can activate the preview
flag:
activate :dato, preview: true
To explicitely read data from a specific environment and not from the primary one you can use the environment
option:
activate :dato, environment: "my-sandbox-environment"
Once the plugin is activated, an object called dato
will be available in your Middleman views to access content coming from your administrative area:
<!-- source/index.html.erb --><h1><%= dato.homepage.title %></h1>
The same object is also available in your config file. To create multiple pages starting from a collection of DatoCMS records, you can use Middleman proxy pages:
# config.rb# activate middleman-dato pluginactivate :dato, live_reload: trueconfigure :development doactivate :livereloadend# due to how middleman 4 collections work (http://bit.ly/2jHZTI9),# always use `dato` inside a `.tap` method block, like this:dato.tap do |dato|# iterate over the "Blog post" records...dato.blog_posts.each do |article|# ...and create a page for each article starting from a template!proxy "/articles/#{article.slug}.html", "/templates/article.html", locals: { article: article }endend# tell Middleman to ignore the templateignore "/templates/article.html.erb"
<!-- source/templates/article.html.erb --><h1><%= article.title %></h1><ul><% article.categories.each do |category| %><li><%= category.name %></li><% end %><ul><div><%= article.content %></div>
Run bundle exec middleman server
and enjoy!
Obviously, that's just a quick tour: you can learn all the details about how to access your records inside your views and config file in the following sections.