2012-08-01 1 views
2

다음 less 코드가 있습니다. 나는 url() 선언에서 변수를 사용할 때 less.js에 한계가 있다는 것을 읽었으므로 두 가지 제안 된 해결 방법을 사용했지만 실제 문제는 변수가 PHP에서 왔고 결코 해석되지 않기 때문에 올바르게 전달되지 않은 것 같습니다. 나는 어쩌면 내가 뭔가 잘못하고 있어요less33에서 PHP의 문자열을 파싱 할 때 적은 변수를 주입 할 수 없습니다.

lessphp을 사용하고

.

PHP 코드

$this->parsed_css = $this->lessc->parse($this->parsed_css, array('fontdir', 'myfontdir')); 

Less 코드

@font-face { 
    font-family: 'FontAwesome'; 
    src: url(%("%s/fontawesome-webfont.eot", @fontdir)); 
    src: url('@{fontdir}/fontawesome-webfont.eot?#iefix') format('embedded-opentype'), 
     url('@{fontdir}/fontawesome-webfont.woff') format('woff'), 
     url('@{fontdir}/fontawesome-webfont.ttf') format('truetype'), 
     url('@{fontdir}/fontawesome-webfont.svgz#FontAwesomeRegular') format('svg'), 
     url('@{fontdir}/fontawesome-webfont.svg#FontAwesomeRegular') format('svg'); 
    font-weight: @fontdir; 
    font-style: normal; 
} 

CSS 출력 변수가 해석되지 않습니다 당신이 볼 수 있듯이

@font-face { 
    font-family:'FontAwesome'; 
    src:url("/fontawesome-webfont.eot"); 
    src:url('/fontawesome-webfont.eot?#iefix') format('embedded-opentype'), url('/fontawesome-webfont.woff') format('woff'), url('/fontawesome-webfont.ttf') format('truetype'), url('/fontawesome-webfont.svgz#FontAwesomeRegular') format('svg'), url('/fontawesome-webfont.svg#FontAwesomeRegular') format('svg'); 
    font-weight:; 
    font-style:normal; 
} 

.

답변

1

원래 질문 (편집에서 삭제하기 전)의 변수 이름은 $font_dir이지만 모든 참조에서 fontdir (밑줄 없음)을 사용하고 있습니다.

같은 array('fontdir' => $font_dir)으로 fontdir 요소에 값을 할당하십시오 :

$this->parsed_css = $this->lessc->parse($this->parsed_css, array('fontdir' => $font_dir, 'myfontdir' => $my_font_dir)); 
+0

(적어도 documentation에 따라) 아니, 난 아니에요에도 변수를 전달하는'$ this-> parsed_css = $ this-> lessc-> 구문 분석하지 ($ this-> parsed_css, array ('fontdir', 'myfontdir'))''나는 나중에 변수를 전달할 것이고, 지금은 하드 코딩 된 것입니다. –

+0

yopu가 맞고 바보예요, array 'fontdir', 'myfontdir')'은'array ('fontdir'=> 'myfontdir')'이어야합니다. 감사! :) –

+0

이름이 필요 없음 = P; 그것은 흔히 저지른 실수입니다. (그리고 나는 많은 시간을 보냈습니다) - 일부 시스템은 인덱스 0 대 1의 키/값 페어링 (원래 있던 것처럼)과 PHP의 '키'=> '값'메쏘드로 수행합니다. – newfurniturey

0

난 그냥 그것을 less를 다운로드 및 테스트 한, 배열 것은 유일한 이유 코드 하는게 아닙니다 '될 것 같지 않습니다 일하고있어.

이 유효하지 않습니다 less 코드

src: url('@{fontdir}/fontawesome-webfont.eot?#iefix') format('embedded-opentype') 
//  ^ ^ Remove these 

//Right 
echo $less->parse("color: @color", 
    array(
     'color' => 'red' 
)); //color:red; 

//Wrong 
echo $less->parse("color: @{color}", 
     array(
      'color' => 'red' 
    )); // (no output) 
+0

아니 sintax 올바른지 (그리고 내가 사용하고있어 야지 밖에서 url()에 연결했기 때문에 필요하다고 생각해.) 나는 더 적은을 위해 변수를 이스케이프 처리하는 것과 같은 모든 작업을하기 위해 약간의 추가 작업을해야했다. 그것은 가지고 있었다 : 내부,하지만 여기에 문제가 배열과 함께했다 –

+0

@ NicolaPeluchetti, 아주 이상한! 나는 당신이 게시 한 것과 똑같은'less' 코드를 테스트했기 때문에 작동하지 않았다. 글쎄, 네가 해결했으면 좋겠다! – Adi