{"id":17333817,"url":"https://github.com/lotfio/caprice","last_synced_at":"2025-10-12T12:25:58.143Z","repository":{"id":54768105,"uuid":"211069554","full_name":"lotfio/caprice","owner":"lotfio","description":":candy: easy weezy templating engine for php :candy:","archived":false,"fork":false,"pushed_at":"2021-09-22T11:30:37.000Z","size":447,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T18:13:42.918Z","etag":null,"topics":["php","silo-framework","silo-php","template-engine","template-literals","templating","templating-language"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lotfio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-26T11:07:50.000Z","updated_at":"2025-02-14T04:28:20.000Z","dependencies_parsed_at":"2022-08-14T02:10:55.398Z","dependency_job_id":null,"html_url":"https://github.com/lotfio/caprice","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotfio%2Fcaprice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotfio%2Fcaprice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotfio%2Fcaprice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lotfio%2Fcaprice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lotfio","download_url":"https://codeload.github.com/lotfio/caprice/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248933340,"owners_count":21185460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","silo-framework","silo-php","template-engine","template-literals","templating","templating-language"],"created_at":"2024-10-15T15:03:08.722Z","updated_at":"2025-10-12T12:25:58.080Z","avatar_url":"https://github.com/lotfio.png","language":"PHP","funding_links":["https://www.paypal.me/lotfio)*"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/lotfio/caprice/blob/master/docs/logo.png\" width=\"200\"  alt=\"caprice Preview\"\u003e\n  \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Licence-MIT-ffd32a.svg\" alt=\"License\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/PHP-8-808e9b.svg\" alt=\"PHP version\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Version-1.1.2-f53b57.svg\" alt=\"Version\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/coverage-98%25-27ae60.svg\" alt=\"Coverage\"\u003e\n    \u003cimg src=\"https://jenkins.lotfio.net/buildStatus/icon?job=caprice+-+ci\" alt=\"Build Status\"\u003e\n    \u003cimg src=\"https://jenkins.lotfio.net/buildStatus/icon?job=caprice+-+Psalm\u0026subject=Psalm\u0026color=darkturquoise\" alt=\"Static Analysis\"\u003e\n    \u003c/p\u003e\n  \u003cp align=\"center\"\u003e\n    \u003cstrong\u003e:candy: easy weezy templating engine for php :candy:\u003c/strong\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n# :fire: Introduction :\nCaprice is PHP templating engine that aims to write clean PHP syntax along side with HTML code.\ncaprice compiles the syntax and generate php files which means no performance loss but a clean html files with a friendly syntax.\n\n# :pushpin: Requirements :\n- PHP 8 or newer versions\n- PHPUnit \u003e= 9 (for testing purpose)\n\n# :ok_hand: Features :\n- easy to use.\n- friendly syntax.\n- caching (one time compile).\n- no performance loss.\n\n# :rocket: Installation \u0026 Use :\n```php\n    composer require lotfio/caprice\n```\n\n# 💥 testing :\n```php\n    composer test\n```\n\n# :pencil2: Usage :\n```php\n\n  use Caprice\\Caprice;\n\n  require 'vendor/autoload.php';\n\n  $caprice = new Caprice;\n\n  // load caprice predefined directives\n  $caprice-\u003eloadPredefinedDirectives();\n\n  // set views location and cache location\n  $caprice-\u003esetCompileLocations('views', 'cache'); \n\n  // helpful for development environment\n  $caprice-\u003eenableRecompile();\n  \n  // file to compile  =\u003e views/test.cap.php\n  // you can remove .cap.php extension for both\n  $compiled = $caprice-\u003ecompile(\"test\");\n\n  require $compiled; // require your compiled file\n```\n# :inbox_tray: Available syntax directives:\n\n### code block\n- you can write any php inside code blocks\n\n```cpp\n    #php\n        $var1 = \"foo\";\n        $var2 = \"bar\";\n        echo $var1 . \" and \" . $var2;\n    #endphp\n```\n\n### echo statement\n```cpp\n    {{ \" hello caprice \" }}\n```\n\n### if statement\n- if only\n```cpp\n   // if statement\n    #if ($condition)\n\n      // logic\n    #endif\n```\n- if else\n```cpp\n   // if statement\n    #if ($condition)\n        // if logic\n    #else\n      // else logic\n    #endif\n```\n- if elseif\n```cpp\n    #if ($condiftion)\n     // if logic\n\n    #elseif ($condition2)\n\n      // elseif logic\n    #else\n      // else logic\n    #endif\n```\n\n### for in loop\n- for in loop value only\n```cpp\n    // for in loop key only\n    #for ($name in $array)\n        {{ $name }}\n    #endforin\n```\n- for in loop key, value\n```cpp\n    // for in loop key value\n    #for ($name =\u003e $age in $array)\n        {{ $name }} =\u003e {{ $age }}\n    #endforin\n```\n\n### for loop\n- for loop syntax\n```cpp\n    // for loop\n    #for ($i = 0; $i \u003c= 10; $i++)\n        {{ $i }} \u003cbr\u003e\n    #endfor\n```\n\n### while loop\n- while loop syntax\n```cpp\n    // while loop\n    #while ($condition)\n        // loop\n    #endwhile\n```\n\n### do while loop\n- do while syntax\n```cpp\n    // do while \n    #do\n        {{ \"do something\" }}\n    #enddo($whileCondition)\n```\n\n### continue \u0026 break loop\n```cpp\n    // continue \u0026 break statements\n    #while (TRUE)\n        #if(condition) #continue #endif\n        #if(another_condition) #break #endif\n    #endwhile\n```\n\n### include / require statements\n```cpp\n    // include/require statements\n    // you can remove .cap.php extension for both\n    // you use . to access folder instead of /\n    #require(\"file.cap.php\")\n    #include(\"file.cap.php\")\n```\n\n### layout\n```cpp\n    // extends a base layout\n    // here we are extending master.cap.php from layouts folder\n    #extends(\"layouts.master\")\n    // load a section\n    #yield(\"sectionName\")\n\n    // define a section\n    #section(\"sectionName\")\n        // section content\n    #endsection\n```\n\n### helpers\n```cpp\n    // functions\n    // dump\n    #dump($variable) OR #dd($variable)\n```\n# :hand: Custom directives:\n - you can define your custom directives:\n - ***make sure that the definition of your directives goes before calling compile***\n ```php\n\n    // simple directives\n    $caprice-\u003edirective(\"#test\", function(){\n        return 'replace test directive with this string';\n    });\n\n    // expression directive\n    // example #call($var)\n    $caprice-\u003edirective(\"#call\", function(string $expression, string $match, array $extras){\n        return '\u003c?php call'. $expression . ';?\u003e'; // this will evaluate to \u003c?php call($var);\\?\\\u003e\n    });\n\n    // class method directive\n    // MyDirective class should implement DirectiveInterface\n    $caprice-\u003edirective(\"#call\", MyDirective::class);\n```\n\n# :helicopter: TODO\n- Adding helpers\n- Adding unit test helpers\n\n# :computer: Contributing\n\n- Thank you for considering to contribute to ***Caprice***. All the contribution guidelines are mentioned [here](CONTRIBUTING.md).\n\n# :page_with_curl: ChangeLog\n\n- Here you can find the [ChangeLog](CHANGELOG.md).\n\n# :beer: Support the development\n\n- Share ***Caprice*** and lets get more stars and more contributors.\n- If this project helped you reduce time to develop, you can give me a cup of coffee :) : **[Paypal](https://www.paypal.me/lotfio)**. 💖\n\n# :clipboard: License\n\n- ***Caprice*** is an open-source software licensed under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flotfio%2Fcaprice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flotfio%2Fcaprice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flotfio%2Fcaprice/lists"}