2014-01-17 1 views
0

JS 및 PHP 모두에 수염을 사용하고 있습니다. JS 용 서식 파일을 하나 만들었으므로 이제 PHP에서 해당 서식 파일을 사용하고 싶습니다. 해당 템플릿을 다시 사용할 수 있습니까? JS 템플릿 : 참고로 JS 및 PHP 용 일반 콧수염 서식 파일

는 아래의 코드를 볼

<table class="table table-bordered table-hover table-striped tablesorter"> 
     <thead> 
      <tr> 
       <th class="header">Name</th> 
       <th class="header">Email ID</th> 
       <th class="header">Contact Number</th> 
       <th class="header">Edit</th> 
      </tr> 
     </thead> 
     <tbody> 
     <div id="eTableList"></div>  
     <script id="eList" type="text/template">  
       <tr> 
        <td>{{name}}</td> 
        <td>{{email}}</td> 
        <td>{{contact_number}}</td> 
        <td><a href="{{id}}">View/Edit</a></td> 
       </tr> 
     </script>  
     </tbody> 
    </table> 

PHP 템플릿 :

<table class="table table-bordered table-hover table-striped tablesorter"> 
     <thead> 
      <tr> 
       <th class="header">Name</th> 
       <th class="header">Email ID</th> 
       <th class="header">Contact Number</th> 
       <th class="header">Edit</th> 
      </tr> 
     </thead> 
     <tbody id="eTableList"> 
       <tr> 
        <td>{{name}}</td> 
        <td>{{email}}</td> 
        <td>{{contact_number}}</td> 
        <td><a href="{{id}}">View/Edit</a></td> 
       </tr> 
     </tbody> 
    </table> 

모두 템플릿의 출력은 동일하지만, 내 필요에 따라 그들을 호출 오전 PHP 또는 JS 사용.

JS와 PHP 두 가지 호출에 모두 사용할 수있는 위의 두 개의 템플릿 대신 단일 템플릿을 사용하는 방법이 있습니까?

답변

0

예, 템플릿의 위치는 서버 측 PHP와 클라이언트 측 JavaScript에서 액세스 할 수 있으므로 가능합니다.

당신은 예를 들어, 공용 액세스의 하위 폴더에있는 템플릿 파일을 할 수 :

public 
-- index.php 
-- assets 
-- -- img (your client side images) 
-- -- css (your styles) 
-- -- templates 
-- -- -- my_template.tpl 
-- -- js (your javascript) 

을 그런 거 상대 경로에서 호출, JS 스크립트에서 사용할 때 ../templates/my_template.tpl , PHP에서는 MY_ROOT_APP_CONSTANT와 같은 절대 경로에서 호출하십시오. "assets/templates/my_template.tpl"

희망이 도움이됩니다.

안부

+0

좋아 멋진 ...하지만 어떻게 당신이 볼 수 모두 템플릿 다른 하나는 PHP 용이고 다른 하나는 JS입니다이기 때문에 일반적인 템플릿을 만드는 방법. – Anubhav

관련 문제