# [Sage 10] Wrong path with dynamic path dirname(__FILE__)

**URL:** https://discourse.roots.io/t/sage-10-wrong-path-with-dynamic-path-dirname-file/21348
**Category:** sage
**Tags:** sage10
**Created:** 2021-08-29T17:23:16Z
**Posts:** 4

## Post 1 by @AurelianSpodarec — 2021-08-29T17:23:16Z

So, here is the thing, when I use ` dirname( __FILE__ )` I expect it to find the path on its own, which it works, however, it has the wrong directory.

What do I mean by that?

 ![image](https://discourse.roots.io/uploads/default/original/2X/7/799b46ef97f9bd757a8092fe81dd67f3cf7f6bbd.png)

Take a look at that path, what it should be is this:

```
/var/www/html/wp-content/themes/TrafikStudioTheme/resources/views/blocks/block-clients.blade.php
```

Note the difference being at `resources/views` - I don’t understand they sage? Has the wrong directory when using a dynamic path.

Otherwise, how will I tell the file to search the path on its own? So far this is annying because I need to comment this each time I push the change, and then change it back so it works on localhost, and its in multiple files I have to do this.

---

## Post 2 by @alwaysblank — 2021-08-29T18:24:17Z

` __FILE__ ` returns the current file being executed. The blade files you create are never actually executed: they are used as markup to generate php files, and _those_ are executed. Those generated php files are in the storage folder you see there.

Can you explain why you need the full system path of a blade? There may be another way to solve your problem.

---

## Post 3 by @AurelianSpodarec — 2021-08-30T06:22:35Z

Right.

Because when I try to grab a file from blocks, a directory I created, it seems I need to get the full path, same goes in digital ocean. So what I do is comment in/out the flexible content path each time on multiple templates.

This is my code:

```
@extends('layouts.app')
@section('content')

{{-- page.blade.php --}}

<?php
//$flexibleContentPath = dirname( __FILE__ ) . '/blocks/';
$flexibleContentPath = $flexibleContentPath = "/var/www/html/wp-content/themes/TrafikStudioTheme/resources/views/blocks/";
//$flexibleContentPath = "C:\\Users\\44775\\Desktop\\WebDevelopment\\Personal\\TrafikStudio\\wp-content\\themes\\TrafikStudioTheme\\resources\\views\\blocks\\"; 
$count = 0;
?>

@if ( have_rows( 'flexible_content' ) ) 
@while ( have_rows( 'flexible_content' ) ) <?php the_row(); ?>

<x-section container="{{ $page[$count]['container'] }}" paddingTop="{{ $page[$count]['paddingTop']}}" paddingBottom="{{ $page[$count]['paddingBottom']}}" bgColor="{{ $page[$count]['backgroundColor'] }}">
@if ( have_rows( 'row' ) )
@while ( have_rows( 'row' ) ) <?php the_row(); ?>
 

    @if ( have_rows( 'column' ) )
    @while ( have_rows( 'column' ) ) <?php the_row(); ?>
    
        <?php 
            $layout = get_row_layout();
            $layoutConverted = str_replace( '_', '-', $layout);
            $file = ( $flexibleContentPath . str_replace( '_', '-', $layout) . '.blade.php' );
        ?>

        @if( file_exists( $file ))
            <?php include($file) ?>
        @else
            <?php echo "File $file with the name of $layoutConverted doesn't exists" ?>    
        @endif 
 
    
    @endwhile
    @endif
    

@endwhile
@endif
</x-section>

<?php $count++ ?>

@endwhile
@endif

@endsection
```

---

## Post 4 by @alwaysblank — 2021-08-30T07:43:54Z

It looks like you’re trying to rebuild basic blade functionality. Why can’t you use `@include( 'blocks.' . $layoutConverted )`? That should have exactly the same result without needing to determine the full path.

---

## Post 5 by @system — 2021-10-10T17:23:19Z

This topic was automatically closed after 42 days. New replies are no longer allowed.
