Search code examples
erbslim-lang

slim multiple lines of logic setup


In ERB I can do this to setup variables:

<%
  skills_list = [
    { var_name: @expert_skills, label: "Expert Skills"
    { var_name: @advanced_skills, label: "Advanced Skills"
    { var_name: @familiar_skills, label: "Familiar Skills"
  ]
%>

How do I accomplish the same thing in slim without putting - at the beginning of each line?


Solution

  • This should do what you need:

    - skills_list = [ \
        { var_name: @expert_skills, label: "Expert Skills" },
        { var_name: @advanced_skills, label: "Advanced Skills" },
        { var_name: @familiar_skills, label: "Familiar Skills"}]
    

    The slash on the first line would not be needed if you put the first hash on the same line because the ending comma would signal to slim that more Ruby follows--but then it would not line up so prettily. That is also why the end ] must be where it is in this example.

    This section of the Slim Docs explains this.