Register new sidebar

Hi. I register new sidebar by adding code on widgets.php

  // Sidebars
 register_sidebar(array(
 'name'          => __('Primary', 'roots'),
'id'            => 'sidebar-primary',
'before_widget' => '<section class="widget %1$s %2$s">',
'after_widget'  => '</section>',
'before_title'  => '<h3>',
'after_title'   => '</h3>',
));

register_sidebar(array(
'name'          => __('Secondary', 'roots'),
'id'            => 'sidebar-secondary',
'before_widget' => '<section class="widget %1$s %2$s">',
'after_widget'  => '</section>',
'before_title'  => '<h3>',
'after_title'   => '</h3>',
));

How can I include it on base.php without copying the code of the Primary Sidebar

    <div class="content row">
      <?php if (roots_display_sidebar()) : ?>
      <aside class="sidebar <?php echo roots_sidebar_class(); ?>" role="complementary">
      <?php include roots_sidebar_path(); ?>
      </aside><!-- /.sidebar -->
    <?php endif; ?>
     <main class="main <?php echo roots_main_class(); ?>" role="main">
    <?php include roots_template_path(); ?>
  </main><!-- /.main -->
  <?php if (roots_display_sidebar()) : ?>
    <aside class="sidebar <?php echo roots_sidebar_class(); ?>" role="complementary">
      <?php include roots_sidebar_path(); ?>
    </aside><!-- /.sidebar -->
  <?php endif; ?>
</div><!-- /.content -->

I want to change it dynamically and different on widgets

Thanks

The primary sidebar in Roots does work a little differently but it doesn’t force you to treat every sidebar that way. You can still include a sidebar as you would in any other theme:

<?php dynamic_sidebar('sidebar-secondary'); ?>

The downside to this is you will have to code your own logic for it.

Is there any other way to do it? or what files should I make changes?

Yes. There are lots of ways to do it but it depends how complex you need it to be.

If it’s appearing on every page then there’s no point duplicating the primary sidebar’s logic and it’s probably best suited to go in base.php (create templates/sidebar-secondary.php and include it).

If you only want the sidebar on certain pages/posts, you can either include from each of those page/post templates or duplicate the code we use from the primary sidebar.

How can I code the sidebar-secondary on the base.php that will be similar to this one?

  <?php if (roots_display_sidebar()) : ?>
    <aside class="sidebar <?php echo roots_sidebar_class(); ?>" role="complementary">
      <?php include roots_sidebar_path(); ?>
    </aside><!-- /.sidebar -->
  <?php endif; ?>

Already got the answer!!!

Thanks for you help Foxaii!

  <?php if (roots_display_sidebar()) : ?>
    <aside class="sidebar <?php echo roots_sidebar_class(); ?>" role="complementary">
      <?php  get_template_part('templates/secondary-sidebar'); ?>
    </aside><!-- /.sidebar -->
  <?php endif; ?>